[PyQt] QTreeWidgetItem also forgets its Python counterpart

Phil Thompson phil at riverbankcomputing.com
Tue Mar 12 09:07:46 GMT 2013


On Tue, 12 Mar 2013 06:42:08 +0100, Wilbert Berendsen <wbsoft at xs4all.nl>
wrote:
> 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

Already fixed.

Phil


More information about the PyQt mailing list