B
B
Bunny Fluffy2017-04-19 16:47:00
Python
Bunny Fluffy, 2017-04-19 16:47:00

How do I test Drag-and-Drop in Qt?

I have a GUI written in PyQt. It actively uses drag-and-drop from one widget to another (we drag objects from the Item View, drop them onto the Graphics Scene).
I want to test my GUI with QTest.
I write code like this:

QtTest.QTest.mouseMove(self.main_wnd.tree_view.viewport(), constant_rect.center(), 300)
        QtTest.QTest.mousePress(self.main_wnd.tree_view.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers(),
                                constant_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)

However, it was not there: yes, the mouse pointer moves where it should be, the desired element in the Item View is selected, and then moved to the center of my scene. But neither the Drag Event nor the Drop Event, unfortunately, happens there.
I have to ask: how to overcome it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question