If I try to use QTest.mouseClick on a QTreeWidget it raises an assert from the C++ library.
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
from PySide import QtCore, QtGui
from PySide.QtCore import Qt
from PySide.QtTest import QTest
app = QtGui.QApplication([])
tree = QtGui.QTreeWidget()
tree.headerItem().setText(0,"")
tree.headerItem().setText(1,"")
tree.headerItem().setText(2,"")
item = QtGui.QTreeWidgetItem(tree)
item.setText(0,"a")
item.setText(1,"b")
item.setText(2,"c")
QTest.mouseClick(tree,Qt.LeftButton,pos=tree.visualItemRect(item).topLeft())
ASSERT: "QTest::testLogger" in file qtestlog.cpp, line 334
Abort trap: 6
I'm using PySide 1.2.2 and I've tried this on both OS X (10.9.3) and Windows7, both with the exact same result.
Am I doing something incorrect or did I discover a PySide bug (I'm fearing that the latter is the case)?
UPDATE:
The suggestion from @Trilarion gave me an idea. I tried adding a parent to the QTreeWidget. Doing that resolved the ASSERT, however the QTreeWidget does not seem to register the emulated click at all.
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
from PySide import QtCore, QtGui
from PySide.QtCore import Qt
from PySide.QtTest import QTest
def click():
global tree,item
print "Start Click"
for x in xrange(0,1000):
for y in xrange(0,1000):
QTest.mouseClick(tree,Qt.LeftButton,pos=QtCore.QPoint(x,y))#tree.visualItemRect(item).topLeft())
print "End click"
def was_clicked():
print "Tree Was Clicked"
def beep():
print "button was clicked"
app = QtGui.QApplication([])
window = QtGui.QWidget()
tree = QtGui.QTreeWidget(window)
tree.headerItem().setText(0,"")
tree.headerItem().setText(1,"")
tree.headerItem().setText(2,"")
item = QtGui.QTreeWidgetItem(tree)
item.setText(0,"a")
item.setText(1,"b")
item.setText(2,"c")
tree.clicked.connect(was_clicked)
button = QtGui.QPushButton(window)
button.clicked.connect(beep)
#Sanity check to make sure that the button is registering the click
QTest.mouseClick(button,Qt.LeftButton)
#Overkill click test, try clicking the tree on every point in a 1000 x 1000 grid
click()
button was clicked
StartClick
EndClick
I also tried running the above code in a unit test, didn't change the outcome.