Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.8.0
-
None
-
069858008 (dev)
Description
https://doc.qt.io/qt-6/qtest.html#mouseDClick says
If delay is specified, the test will wait for the specified amount of milliseconds before each press and release.
And the docs for mouseClick() say
If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.
Now look at the code:
static void mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1) { QTEST_ASSERT(window); extern int Q_TESTLIB_EXPORT defaultMouseDelay(); // pos is in window local coordinates const QSize windowSize = window->geometry().size(); if (windowSize.width() <= pos.x() || windowSize.height() <= pos.y()) { qWarning("Mouse event at %d, %d occurs outside target window (%dx%d).", pos.x(), pos.y(), windowSize.width(), windowSize.height()); } int actualDelay = (delay == -1 || delay < defaultMouseDelay()) ? defaultMouseDelay() : delay; lastMouseTimestamp += qMax(1, actualDelay); if (pos.isNull()) pos = QPoint(window->width() / 2, window->height() / 2); QTEST_ASSERT(!stateKey || stateKey & Qt::KeyboardModifierMask); stateKey &= Qt::KeyboardModifierMask; QPointF global = window->mapToGlobal(pos); QPointer<QWindow> w(window); using namespace QTestPrivate; switch (action) { case MouseDClick: qtestMouseButtons.setFlag(button, true); qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonPress, stateKey, lastMouseTimestamp); qtestMouseButtons.setFlag(button, false); qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonRelease, stateKey, lastMouseTimestamp); Q_FALLTHROUGH(); case MousePress: case MouseClick: qtestMouseButtons.setFlag(button, true); qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonPress, stateKey, lastMouseTimestamp); if (action == MousePress) break; Q_FALLTHROUGH(); case MouseRelease: qtestMouseButtons.setFlag(button, false); qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonRelease, stateKey, lastMouseTimestamp); if (delay == -1) lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated break;
The delay argument is only added once, at the beginning. It does not get added during each call to qt_handleMouseEvent(). We just add it once and then keep using lastMouseTimestamp for each event in the sequence. This does not realistically simulate how users interact with the mouse.
The docs are very old. So it's always been this way in Qt 5, and probably long before.
When we change it, we might expect some timestamp-sensitive tests to fail. OTOH it has sometimes been hard to write realistic tests because of this.
Attachments
Issue Links
- relates to
-
QTBUG-111336 [REG 6.3->6.4] qtdeclarative/examples/quick/pointerhandlers/tabletCanvasDrawing.qml got broken again
- Closed
-
QTBUG-125993 Double tap on touch screen not provoking mouseDoubleClickEvent - patch included
- Closed
-
QTBUG-95421 need the ability to delay (increment timestamps of) touch events, as with mouse events
- Reported
-
QTBUG-102441 QuickTest cannot double-click TapHandler
- Closed
-
QTBUG-126519 it's not useful that defaultMouseDelay() in QTestLib is 0 by default
- Open