[PyQt] Can't set icon on QTreeWidgetItem

Baz Walter bazwal at ftml.net
Sat Nov 21 19:05:21 GMT 2009


Filip Gruszczyński wrote:
> I am trying to set an icon on QTreeWidgetItem and I can't achieve
> this. The icon simply doesn't appear. The code is short:
> 
> class MessageBoxSelect(QTreeWidget):
> 
> 	
> 
> 	def __init__(self, parent=None):
> 
> 		QTreeWidget.__init__(self, parent)
> 
> 		self.setRootIsDecorated(True)
> 
> 		self.setColumnCount(1)
> 
> 		self.setIconSize(QSize(12, 12))
> 
> 		self.model().setHeaderData(0, Qt.Horizontal,
> 
> 								   self.tr(u"Wszystkie foldery"))
> 
> 		
> 
> 		self.root = QTreeWidgetItem()
> 
> 		self.root.setText(0, self.tr(u'Lokalne foldery'))
> 
> 		self.root.setIcon(0, QIcon(':/images/registration.png'))
> 
> 		self.addTopLevelItem(self.root)
> 
> Could anyone help me?

if i replace

	self.root.setIcon(0, QIcon(':/images/registration.png'))

with

         icon = self.style().standardIcon(QStyle.SP_DirIcon)
         self.root.setIcon(0, icon)

then it works fine for me.

are you sure that the resource ":/images/registration.png" exists?




More information about the PyQt mailing list