在QTreeWidget上执行QTest.mouseClick时,PySide断言

时间:2014-06-05 22:16:31

标签: python qt pyside qtestlib

如果我尝试在QTreeWidget上使用QTest.mouseClick,它会从C ++库中引发一个断言。

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

我正在使用PySide 1.2.2并且我已经在OS X(10.9.3)和Windows7上都尝试了这一点,两者都具有完全相同的结果。

我做错了什么或者我发现了PySide错误(我担心后者是这种情况)?

更新:

@Trilarion的建议给了我一个主意。我尝试将父级添加到QTreeWidget。这样做解决了ASSERT,但QTreeWidget似乎根本没有注册模拟点击。

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

我也尝试在单元测试中运行上面的代码,但没有改变结果。

0 个答案:

没有答案