PDA

View Full Version : Displaying icon in tableView



JPNaude
13th October 2008, 17:35
Hi

I'm trying to display an icon in a tableview cell. I've search this forum but only found one thread related to it:
http://www.qtcentre.org/forum/showthread.php?t=6136&highlight=icon+tableview

However this does not help me since that was a tableWidget. I've created a model class inheriting from QAbstractTableModel and in the data() function I'm trying to return a QIcon. I thought this would work since the data function returns a QVariant which should suit a QIcon.

This is the code that is located in my model's data function:


if (role == Qt::DisplayRole) {
QIcon icon = QIcon(":/images/error.png");
return icon
}


Am I missing something? Can I use a .png file? This should be pretty easy to do shouldn't it?

Thanks
Jaco

spirit
13th October 2008, 17:44
did you have resource file? is it included in pro file?

caduel
13th October 2008, 18:22
return the icon for the Qt::DecorationRole

JPNaude
14th October 2008, 08:28
Yes I had the resource file. I did not have the correct prefix in the resource file, and I also didn't return the icon under the DecorationRule. It works now.

Thanks
Jaco