diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2018-08-23 14:00:01 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-03-04 12:39:53 +0000 |
commit | 1c7213dbc00fa595aeaa98ad5631bac56782599e (patch) | |
tree | a2821c20fccb994693c4bd41686fd22225bc53ae /tests | |
parent | 042f2b67739439c020451843d887d131d5f9cbdc (diff) |
Fix a bug where hover events were not sent if the mouse was never moved
This happened if the "real mouse" was never moved, since moving the real
mouse caused it to update the internal
QQuickWindowPrivate::lastMousePosition. If the window never got any
mouse events, it would therefore fail to generate proper hover events.
However, if the window got exposed under a mouse cursor it would generate
a hover enter event. We therefore update lastMousePosition when that
happens also.
Change-Id: I77d9b1bd779a813756c4056b015f2e81664b6d36
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
3 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/lesHoverables.qml b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/lesHoverables.qml index 9045247e94..011dc4e75f 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/lesHoverables.qml +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/lesHoverables.qml @@ -90,7 +90,7 @@ Rectangle { id: paddle objectName: "paddle" width: 100 - height: 40 + height: 100 color: paddleHH.hovered ? "indianred" : "#888" x: (parent.width - width) / 2 y: parent.height - 100 diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index 52074aec4f..f141a2546c 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -60,6 +60,7 @@ private slots: void hoverHandlerAndUnderlyingHoverHandler(); void mouseAreaAndUnderlyingHoverHandler(); void hoverHandlerAndUnderlyingMouseArea(); + void movingItemWithHoverHandler(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); @@ -229,6 +230,42 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingMouseArea() QCOMPARE(buttonHoveredSpy.count(), 2); } +void tst_HoverHandler::movingItemWithHoverHandler() +{ + if (isPlatformWayland()) + QSKIP("Wayland: QCursor::setPos() doesn't work."); + + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "lesHoverables.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem * paddle = window->rootObject()->findChild<QQuickItem *>("paddle"); + QVERIFY(paddle); + QQuickHoverHandler *paddleHH = paddle->findChild<QQuickHoverHandler *>("paddleHH"); + QVERIFY(paddleHH); + + // Find the global coordinate of the paddle + const QPoint p(paddle->mapToScene(paddle->clipRect().center()).toPoint()); + const QPoint paddlePos = window->mapToGlobal(p); + + // Now hide the window, put the cursor where the paddle was and show it again + window->hide(); + QTRY_COMPARE(window->isVisible(), false); + QCursor::setPos(paddlePos); + window->show(); + QTest::qWaitForWindowExposed(window); + + QTRY_COMPARE(paddleHH->isHovered(), true); + + paddle->setX(100); + QTRY_COMPARE(paddleHH->isHovered(), false); + + paddle->setX(p.x()); + QTRY_COMPARE(paddleHH->isHovered(), true); + + paddle->setX(540); + QTRY_COMPARE(paddleHH->isHovered(), false); +} + QTEST_MAIN(tst_HoverHandler) #include "tst_qquickhoverhandler.moc" diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index 42dc766a13..aaf37b32cd 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -569,7 +569,10 @@ void tst_qquickwidget::mouseEventWindowPos() QVERIFY(!rootItem->property("wasClicked").toBool()); QVERIFY(!rootItem->property("wasDoubleClicked").toBool()); - QVERIFY(!rootItem->property("wasMoved").toBool()); + // Moving an item under the mouse cursor will trigger a mouse move event. + // The above quick->move() will trigger a mouse move event on macOS. + // Discard that in order to get a clean slate for the actual tests. + rootItem->setProperty("wasMoved", QVariant(false)); QWindow *window = widget.windowHandle(); QVERIFY(window); |