[PyQt] QTreeWidgetItem also forgets its Python counterpart

Wilbert Berendsen wbsoft at xs4all.nl
Tue Mar 12 05:42:08 GMT 2013


Hi,

I am having a similar bug indeed in sip-4.14.3 / PyQt-4.9.6 where
QTreeWidgetItem forgets its Python state when created with a
QTreeWidget().invisibleRootItem() as parent.

After importing * from PyQt4.QtCore and QtGui:

>>> app=QApplication([])
>>> w=QTreeWidget()
>>> class Item(QTreeWidgetItem):
...   pass
... 
>>> i=Item(w.invisibleRootItem())
>>> i.value=123
>>> del i
>>> w.topLevelItem(0)
<PyQt4.QtGui.QTreeWidgetItem object at 0xb69ceadc>
>>> w.topLevelItem(0).value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'QTreeWidgetItem' object has no attribute 'value'

But when I create Item with the treewidget itself as parent, it works:

>>> w.clear()
>>> i=Item(w)
>>> del i
>>> w.topLevelItem(0)
<__main__.Item object at 0xb69ce614>

And when I create an Item with a toplevel Item as parent, it also
works:

>>> j=Item(w.topLevelItem(0))
>>> w.topLevelItem(0).child(0)
<__main__.Item object at 0xb69ceadc>
>>> del j
>>> w.topLevelItem(0).child(0)
<__main__.Item object at 0xb69ceadc>
>>> w.topLevelItem(0).child(0).value=123
>>> w.topLevelItem(0).child(0).value
123
>>> 

So the bug is only that when creating a QTreeWidgetItem (even if
derived) with the QTreeWidget.invisibleRootItem() as parent, its Python
counterpart is forgotten and a new wrapped object is created.

Wilbert

-- 
Wilbert Berendsen
(http://www.wilbertberendsen.nl)



More information about the PyQt mailing list