1

PySide でアプリケーションを開発しています。アプリケーションにコードを記述する前に、単体テストを行っています。QTreeWidget 内のアイテムを選択する必要があるのでQTreeWidget.currentItem、ユニット テストに合格するために、それを取得して何かを行うことができますQTest.mouseClick。 QTreeWidget。

4

2 に答える 2

2

あなたが望むのは、からクリックしてメソッドQModelIndexを使用するviewport()ことです:

def clickIndex(tree_view, index):
    model = tree_view.model()
    # If you have some filter proxy/filter, don't forget to map
    index = model.mapFromSource(index)
    # Make sure item is visible
    tree_view.scrollTo(index)
    item_rect = tree_view.visualRect(index)
    QTest.mouseClick(tree_view.viewport(), Qt.LeftButton, Qt.NoModifier, item_rect.center())
于 2015-01-13T03:31:28.013 に答える
1

を使用せずに、私が望んでいたことを達成することができましたQTest.mouseClick

コードは次のとおりです。

from src import ui
from nose.tools import eq_
from PySide.QtCore import Qt
from PySide.QtTest import QTest

if QtGui.qApp is None:
    QtGui.QApplication([])

appui = ui.Ui()

# ...

def test_movedown_treewidget():
    item = appui.tblURLS.topLevelItem(0)
    appui.tblURLS.setCurrentItem(item)
    QTest.mouseClick(appui.pbtMoveDOWN, Qt.LeftButton)
    # After that click, the connected slot was executed
    # and did something with the current selected widget
    item = appui.tblURLS.topLevelItem(0)

    eq_(item.text(2), u"http://www.amazon.com/example2")


def test_moveup_treewidget():
    item = appui.tblURLS.topLevelItem(1)
    appui.tblURLS.setCurrentItem(item)
    QTest.mouseClick(appui.pbtMoveUP, Qt.LeftButton)
    # After that click, the connected slot was executed
    # and did something with the current selected widget
    item = appui.tblURLS.topLevelItem(0)

    eq_(item.text(2), u"http://www.amazon.com/example1")

# ...
于 2014-06-13T22:57:06.663 に答える