Created attachment 340186 [details] qtreewidget click test case In PyQt4-4.9.6 / qt-4.8.4 as provided by Gentoo, QTreeWidget gives the wrong items when clicking them. Attached test script creates a QTreeWidget with 9 items and prints them as you click them. It works for foo/bar/baz (using QTreeWidgetItem.__init__(parent)) but doesn't work for qfoo/myfoo which were added using parent.addChild(item). This code works fine on Ubuntu/Windows. So it somehow affects Gentoo or PyQt/Qt version used by Gentoo. It creates these QTreeWidgetItems: foo is <__main__.MyTreeItem object at 0x197c7a0> bar is <__main__.MyTreeItem object at 0x197c830> baz is <__main__.MyTreeItem object at 0x197c8c0> qfoo is <PyQt4.QtGui.QTreeWidgetItem object at 0x197c9e0> qbar is <PyQt4.QtGui.QTreeWidgetItem object at 0x197c950> qbaz is <PyQt4.QtGui.QTreeWidgetItem object at 0x197c9e0> myfoo is <__main__.MyTreeItem object at 0x197ca70> mybar is <__main__.MyTreeItem object at 0x197c950> mybaz is <__main__.MyTreeItem object at 0x197ca70> Clicking them in the same order gives these items: foo click <__main__.MyTreeItem object at 0x197c7a0> bar click <__main__.MyTreeItem object at 0x197c830> baz click <__main__.MyTreeItem object at 0x197c8c0> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> None click <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> Somehow <__main__.MyTreeItem object at 0x197ca70> turns into <PyQt4.QtGui.QTreeWidgetItem object at 0x197ca70> (same address), item lost its properties, and the signal gets this same item even if you click different ones. Ubuntu/Windows gives qfoo/qbar/qbaz/myfoo/mybar/mybaz instead of None/None/... Same thing happens when you try to use doubleclick / itemchanged signals.
I forgot to mention: This bug affects app-misc/anki-2.0.8 which is written using PyQt and uses QTreeWidget for its card browser. Next version of app-misc/anki will probably include a workaround: https://github.com/dae/anki/commit/f13d0c329fbfbc34e4e7630031ddf0547135686c but that doesn't fix the PyQt/Qt bug itself
It might be some garbage collection issue. I just found out that if I add the items to a global list, it keeps working.
Have you reported the issue to PyQt4 mailing list?
I did ask in the PyQt FreeNode channel, but all I got there was "It's probably Qt" Can you reproduce the issue? Cause whoever was in the FreeNode channel, couldn't. I'm not familiar with the Qt universe at all, sorry for offloading it on to you...
The testcase works with pyside, so it's not qt's fault.
(In reply to comment #4) > I did ask in the PyQt FreeNode channel, but all I got there was "It's > probably Qt" > > Can you reproduce the issue? Cause whoever was in the FreeNode channel, > couldn't. > > I'm not familiar with the Qt universe at all, sorry for offloading it on to > you... Just post your issue + the testcase to this ML http://www.riverbankcomputing.co.uk/mailman/listinfo/pyqt Phil (upstream dev) is usually very helpful and responsive.
It seems someone already did that for me after all: http://python.6.n6.nabble.com/QTreeWidgetItem-addChild-no-longer-keeping-references-td5008839.html
Good! And it seems it has already been fixed upstream (the fix should appear in PyQt4-4.10.1), hence I'm closing as such.