PDA

View Full Version : Easiest way to display icons in a table



ghorwin
16th March 2007, 20:36
Hi there,

while using a TableView and costum item delegates would be one way to display Icons in a table, I suspect there is a simpler way, possibly even with QTableWidget.

However, when I simply create a new QTableWidgetItem with an Icon and insert it into the table, it won't be shown.

The code below doesn't will insert a table widget item, but won't show the icon.


QTableWidgetItem * iconItem = new QTableWidgetItem(QIcon(":/images/ok.png"), "");
table->setItem(row, 0, iconItem);


So, what would be the correct (and simplest) way to show Icons in a Table?

jpn
16th March 2007, 21:28
Something pretty much similar works fine for me. I'm suspecting that the image just cannot be loaded. Is the usage of resources intentional? Are the resources compiled correctly? Do you have a line similar to:
RESOURCES += <something>.qrc in the .pro file? RCC would give an error in case the image couldn't be found.

Jimmy2775
16th March 2007, 23:09
If you're using a TableView you can simply return a QIcon in your QAbstractItemModel's data function. That should display the icon you want in the table.

ghorwin
19th March 2007, 14:09
Something pretty much similar works fine for me. I'm suspecting that the image just cannot be loaded.

Yes, that was it. Works now as it is supposed to. Thanks!