I am using QTreeWidget, where I would like to add icon to each item (for easier user use). I have tried all the known ways (at least to me), such as:
- https://forum.qt.io/topic/14858/using-icons-with-qtreewidgetitem
- https://forum.qt.io/topic/88992/qtreewidget-icons-issue
- https://www.qtcentre.org/threads/9155-how-to-add-icons-to-QTreeWidget
- pyqt5 I want to remove arrow icon in QTreeWidget
- Position of icon in QTreeWidgetItem
- How to set the icon-size in a QTreeWidget?
However, none of the proposed ways worked. Not even using custom jpg (in case themes are messed up). Extract of my code is below:
print("add folder")
text, ok = QtWidgets.QInputDialog.getText(self.app, "Add new folder","New folder name:")
child = ProjectBrowserItem([text],ProjectBrowserItemType.FOLDER) #this is QTreeWidgetItem
child.setForeground(0,QtGui.QBrush((QtGui.QColor("#996633")))) #this is just to see if I can modify QTreeWidgetItem properties
icon = QtGui.QIcon("folder.jpg") #this is my custom 32x32 pixel icon
child.setIcon(0,icon) #setting the icon
print(child.icon(0)) #just to see whether icon exists
item.addChild(child) #adding new child to the parent item
item.setExpanded(True) #expand everything
self.show() #show the tree
and my printout:
and my icon (if needed):
However, this icon does not appear on my QTreeWidget. The result is following:
As you see, no icon is added to the item Folder.
Am I missing something? Is there some additional update/resizing needed?
FYI, adding icons to buttons doesnt work either.
Thanks!!