diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h index fe89f371ca..26d3b50145 100644 --- a/src/testlib/qtestmouse.h +++ b/src/testlib/qtestmouse.h @@ -206,29 +206,36 @@ namespace QTest stateKey &= static_cast(Qt::KeyboardModifierMask); QEvent::Type meType; - Qt::MouseButton meButton; + using namespace QTestPrivate; switch (action) { case MousePress: + qtestMouseButtons.setFlag(button, true); meType = QEvent::MouseButtonPress; - meButton = button; break; case MouseRelease: + qtestMouseButtons.setFlag(button, false); meType = QEvent::MouseButtonRelease; - meButton = Qt::MouseButton(); break; case MouseDClick: + qtestMouseButtons.setFlag(button, true); meType = QEvent::MouseButtonDblClick; - meButton = button; break; case MouseMove: - QCursor::setPos(widget->mapToGlobal(pos)); - qApp->processEvents(); - return; + // ### Qt 7: compatibility with < Qt 6.3, we should not rely on QCursor::setPos + // for generating mouse move events, and code that depends on QCursor::pos should + // be tested using QCursor::setPos explicitly. + if (qtestMouseButtons == Qt::NoButton) { + QCursor::setPos(widget->mapToGlobal(pos)); + qApp->processEvents(); + return; + } + meType = QEvent::MouseMove; + break; default: QTEST_ASSERT(false); } - QMouseEvent me(meType, pos, widget->mapToGlobal(pos), button, meButton, stateKey, QPointingDevice::primaryPointingDevice()); + QMouseEvent me(meType, pos, widget->mapToGlobal(pos), button, qtestMouseButtons, stateKey, QPointingDevice::primaryPointingDevice()); me.setTimestamp(lastMouseTimestamp); if (action == MouseRelease) // avoid double clicks being generated lastMouseTimestamp += mouseDoubleClickInterval;