I have a GUI with QTreeView and QGraphicsSceneView.
The model used by the tree view supports drag events and graphics scene supports drop events.
I want to simulate user actions with QTest: mousePress
, mouseMove
, mouseRelease
and so on.
I write this code:
item_rect = self.main_wnd.tree_view.visualRect(constant_index)
QtTest.QTest.mouseMove(self.main_wnd.tree_view.viewport(), item_rect.center(), 300)
QtTest.QTest.mousePress(self.main_wnd.tree_view.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers(),
item_rect.center(), 300)
QtTest.QTest.mouseMove(self.main_wnd._scene_views[None].viewport(), QtCore.QPoint(), 300)
QtTest.QTest.mouseRelease(self.main_wnd.tree_view.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers(),
constant_rect.center(), 300)
Here my mouse really moves to the tree item rect, selects it -- and moves to the center of the scene without any dragging or dropping.
Can you tell me, how can I fix it?