From 2b50181be816094325adef6e9610b8dd9a03d6a8 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 8 Dec 2021 18:06:35 +0100 Subject: Add HoverHandler.blocking property As with WheelHandler, sometimes users want to let the hover events propagate (which has been the default all along), but sometimes it's not appropriate to allow parents of nested items to show hover feedback. [ChangeLog][QtQuick][HoverHandler] HoverHandler now has a property called blocking, which is false by default; but if set to true, it prevents hover events from propagating to items "under" this handler's parent, and their HoverHandlers. Task-number: QTBUG-85926 Change-Id: I26f89482e294c7a6b30a55a7e23ac444a0d1ac7f Reviewed-by: Richard Moe Gustavsen --- .../qquickhoverhandler/tst_qquickhoverhandler.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp') diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index 8e92714a84..5cafaf42ea 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -58,6 +58,7 @@ public: {} private slots: + void hoverHandlerAndUnderlyingHoverHandler_data(); void hoverHandlerAndUnderlyingHoverHandler(); void mouseAreaAndUnderlyingHoverHandler(); void hoverHandlerAndUnderlyingMouseArea(); @@ -82,8 +83,18 @@ void tst_HoverHandler::createView(QScopedPointer &window, const char QVERIFY(window->rootObject() != nullptr); } +void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler_data() +{ + QTest::addColumn("blocking"); + + QTest::newRow("default: nonblocking") << false; + QTest::newRow("blocking") << true; +} + void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() { + QFETCH(bool, blocking); + QScopedPointer windowPtr; createView(windowPtr, "lesHoverables.qml"); QQuickView * window = windowPtr.data(); @@ -96,6 +107,9 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() QQuickHoverHandler *buttonHH = button->findChild("buttonHH"); QVERIFY(buttonHH); + QCOMPARE(buttonHH->isBlocking(), false); // default property value + buttonHH->setBlocking(blocking); + QPoint buttonCenter(button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); QPoint rightOfButton(button->mapToScene(QPointF(button->width() + 2, button->height() / 2)).toPoint()); QPoint outOfSidebar(topSidebar->mapToScene(QPointF(topSidebar->width() + 2, topSidebar->height() / 2)).toPoint()); @@ -121,8 +135,8 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() #endif QTest::mouseMove(window, buttonCenter); - QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(topSidebarHH->isHovered(), !blocking); + QCOMPARE(sidebarHoveredSpy.count(), blocking ? 2 : 1); QCOMPARE(buttonHH->isHovered(), true); QCOMPARE(buttonHoveredSpy.count(), 1); #if QT_CONFIG(cursor) @@ -131,7 +145,7 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() QTest::mouseMove(window, rightOfButton); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.count(), blocking ? 3 : 1); QCOMPARE(buttonHH->isHovered(), false); QCOMPARE(buttonHoveredSpy.count(), 2); #if QT_CONFIG(cursor) @@ -140,7 +154,7 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() QTest::mouseMove(window, outOfSidebar); QCOMPARE(topSidebarHH->isHovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 2); + QCOMPARE(sidebarHoveredSpy.count(), blocking ? 4 : 2); QCOMPARE(buttonHH->isHovered(), false); QCOMPARE(buttonHoveredSpy.count(), 2); #if QT_CONFIG(cursor) -- cgit v1.2.3