aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/pointerhandlers/qquickhoverhandler
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2018-08-23 14:00:01 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-03-04 12:39:53 +0000
commit1c7213dbc00fa595aeaa98ad5631bac56782599e (patch)
treea2821c20fccb994693c4bd41686fd22225bc53ae /tests/auto/quick/pointerhandlers/qquickhoverhandler
parent042f2b67739439c020451843d887d131d5f9cbdc (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/auto/quick/pointerhandlers/qquickhoverhandler')
-rw-r--r--tests/auto/quick/pointerhandlers/qquickhoverhandler/data/lesHoverables.qml2
-rw-r--r--tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp37
2 files changed, 38 insertions, 1 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"