[PyQt] identify a QTreeWidgetItem

Jim Bublitz jbublitz at nwinternet.com
Tue Oct 23 17:59:03 BST 2007


On Tuesday 23 October 2007 02:13, alteo_gange wrote:
> Hi everybody!
>
> I have created several QTreeWidgetItem and connected a signal
> "itemClicked(QTreeWidgetItem *,int)" on the QTreeWidget.
>
> > treeWidget=QtGui.QTreeWidget(widget)
> > ...
> > itemTree1=QtGui.QTreeWidgetItem(treeWidget)
> > ...
> > itemTree2=QtGui.QTreeWidgetItem(treeWidget)
> > ...
> > self.connect(treeWidget,QtCore.SIGNAL("itemClicked(QTreeWidgetItem
> > *,int)"),self.function)
> > ...
> > def function(self, item):
> >         print item
>
> 'print item' return:
> <PyQt4.QtGui.QTreeWidgetItem object at 0x82cf62c>.
>
>
> It's very abstract!
>
> I must identify QTreeWidgetItem in order to connect it an action (view a
> widget on the right), but how? With a method of the item reference? Which?
> I don't know.

Store the items in a dict as you create them:

self.itemDict = {}
itemTree1=QtGui.QTreeWidgetItem(treeWidget)
self.itemDict [itemTree1] = ??  # could be the associated widget that you want          
                                                       #  to connect to, or a                            
                                                       # string identifier
itemTree2=QtGui.QTreeWidgetItem(treeWidget)
self.itemDict [itemTree2] = ??

...

def function (self, item):
	widget = self.itemDict [item]
	...

Jim


More information about the PyQt mailing list