6

I try to test drag&drop with simple sequince: mousePress + mouseMove + mouseRelease. But it's not work.

I investigate qtest source and found, that move event tested through main dispatcher processEvent(). Also I found some bugs in qt bug-tracker: 1, 2

So, I think, that it's not possible to test drag&drop under latest stable Qt4. Have anybody success story with this?

Aleksey Bakin
  • 1,506
  • 13
  • 27

2 Answers2

0

I have had no luck simulating drag and drop via the QTest mouse functions, and digia says they're not adding that functionality to QT4. I implemented drag/drop testing via a method similar to the one suggested in the above link:

create your mime_data, something like:

mime_data = widget_model.mimeData(indexes)

or

mime_data = QMimeData()
mime_data.setText(widget.text())

then use a function like this to drop the data:

def dropOnto(self, widget, mime_data):
    action = Qt.CopyAction|Qt.MoveAction
    pt = widget.rect().center()
    drag_drop = QDropEvent(pt, action, mime_data, Qt.LeftButton, Qt.NoModifier)
    drag_drop.acceptProposedAction()
    widget.dropEvent(drag_drop)
taynaron
  • 704
  • 1
  • 10
  • 23
0

mouseMoveEvent() handler starts and blocks at QDrag.exec(). In order to simulate the drop, you have to schedule it e.g. with QTimer:

def complete_qdrag_exec():
    QTest.mouseMove(drop_target)
    QTest.qWait(50)
    QTest.mouseClick(drop_target, Qt.MouseButton.LeftButton)

QTimer.singleShot(1000, complete_qdrag_exec)
QTest.mousePress(drag_source, Qt.MouseButton.LeftButton, Qt.KeyboardModifier.NoModifier, QPoint(10, 10))
QTest.mouseMove(drag_source, QPoint(50, 50))  # Ensure distance sufficient for DND start threshol
K3---rnc
  • 6,717
  • 3
  • 31
  • 46