SetIcon for QTreeWidgetItem
-
Here is a code when everything is work:
@QTreeWidgetItem *item = rootItem->child(i);if (item == NULL) {
rootItem->addChild(new QTreeWidgetItem());
item = rootItem->child(i);
}item->setData(1,Qt::UserRole, 0);
item->setIcon(1,QPixmap(":/Images/New.png"));item->setText(1,"Some text");@ The text is shown and the icon too. Now code like this will not work: @QTreeWidgetItem * item = new QTreeWidgetItem();
item->setIcon(1,QPixmap(":/Images/New.png"));
item->setData(1,Qt::UserRole,1);item->setData(1,Qt::DisplayRole,"Some text");
parent->addChild(item);@
The text is shown but the icon - not. If i use QApplication::windowIcon() in set icon in second variant of code it works, but ofcourse with application icon, not mine. Maybe it's connected with resource system ? -
In second code I replace @item->setIcon(1,QPixmap(":/Images/New.png"));@ by @item->setIcon(1,QIcon(":/Images/New.png"));@ and now it's begin to work. But what that was ? All these two piece of code is in on class and currently used. Second piece I add after upgrading to MSVS 2010. But even when I change image in first piece(writed in MSVS 2008) to different from resources it still works.