aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-03-14 12:16:33 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-04-05 14:09:37 +0000
commit2da5d5468bd2e245c7d473d753a09cf90e1205ff (patch)
tree9c443eddd565e8b097acf109a72d9063ccac6c52
parentbc93b587e655d21ceac06c9ab03f6c919e8a4f46 (diff)
QQuickMouseArea: let MouseArea reject hover events
From testing Qt 6.1, a MouseArea should not accept hover events, and as such, block hover events from propagating. This patch will make sure that QQuickMouseArea rejects hover events, and thereby restore the behavior Qt had up till Qt 6.1. Fixes: QTBUG-95726 Fixes: QTBUG-95398 Change-Id: I1b929092a3004dd47ef1b6d1a957837ccedc7390 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 56a075341514db1242a0852ccf0fbe98e1fcabbc) Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
-rw-r--r--src/quick/items/qquickmousearea.cpp30
-rw-r--r--tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp9
-rw-r--r--tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp8
3 files changed, 14 insertions, 33 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index d9d9f32c11..303ccb1ce2 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -849,14 +849,8 @@ void QQuickMouseArea::hoverEnterEvent(QHoverEvent *event)
me.setPosition(d->lastPos);
}
- if (auto parentMouseArea = qobject_cast<QQuickMouseArea *>(parentItem())) {
- if (parentMouseArea->acceptHoverEvents()) {
- // Special legacy case: if our parent is another MouseArea, and we're
- // hovered, the parent MouseArea should be hovered too. We achieve this
- // by simply ignoring the event to not block propagation.
- event->ignore();
- }
- }
+ // A MouseArea should not block hover events
+ event->ignore();
}
void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event)
@@ -876,14 +870,8 @@ void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event)
emit positionChanged(&me);
}
- if (auto parentMouseArea = qobject_cast<QQuickMouseArea *>(parentItem())) {
- if (parentMouseArea->acceptHoverEvents()) {
- // Special legacy case: if our parent is another MouseArea, and we're
- // hovered, the parent MouseArea should be hovered too. We achieve this
- // by simply ignoring the event to not block propagation.
- event->ignore();
- }
- }
+ // A MouseArea should not block hover events
+ event->ignore();
}
void QQuickMouseArea::hoverLeaveEvent(QHoverEvent *event)
@@ -894,14 +882,8 @@ void QQuickMouseArea::hoverLeaveEvent(QHoverEvent *event)
else
setHovered(false);
- if (auto parentMouseArea = qobject_cast<QQuickMouseArea *>(parentItem())) {
- if (parentMouseArea->acceptHoverEvents()) {
- // Special legacy case: if our parent is another MouseArea, and we're
- // hovered, the parent MouseArea should be hovered too. We achieve this
- // by simply ignoring the event to not block propagation.
- event->ignore();
- }
- }
+ // A MouseArea should not block hover events
+ event->ignore();
}
#if QT_CONFIG(wheelevent)
diff --git a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
index fff1558bde..ffc0cc333d 100644
--- a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
+++ b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
@@ -194,19 +194,18 @@ void tst_MouseAreaInterop::hoverHandlerDoesntHoverOnPress() // QTBUG-72843
QTRY_COMPARE(handler->isHovered(), true);
// move the mouse into the "button"
QTest::mouseMove(&window, p);
- // current behavior: the mouse is still within the HoverHandler's region of interest, but MouseArea is obstructing.
- QTRY_COMPARE(handler->isHovered(), false);
+ // both the hoverhandler and the mouse area should now be hovered!
+ QTRY_COMPARE(handler->isHovered(), true);
QCOMPARE(ma->hovered(), true);
- // So HoverHandler is no longer hovered (unfortunately). Clicking should not change it.
QSignalSpy hoveredChangedSpy(handler, SIGNAL(hoveredChanged()));
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
QTRY_COMPARE(ma->pressed(), true);
- QCOMPARE(handler->isHovered(), false);
+ QCOMPARE(handler->isHovered(), true);
QCOMPARE(hoveredChangedSpy.count(), 0);
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
QTRY_COMPARE(ma->pressed(), false);
- QCOMPARE(handler->isHovered(), false);
+ QCOMPARE(handler->isHovered(), true);
QCOMPARE(hoveredChangedSpy.count(), 0);
}
diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp
index d4ce666c4d..9b11f8170b 100644
--- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp
@@ -206,8 +206,8 @@ void tst_HoverHandler::mouseAreaAndUnderlyingHoverHandler()
#endif
QTest::mouseMove(window, buttonCenter);
- QCOMPARE(topSidebarHH->isHovered(), false);
- QCOMPARE(sidebarHoveredSpy.count(), 2);
+ QCOMPARE(topSidebarHH->isHovered(), true);
+ QCOMPARE(sidebarHoveredSpy.count(), 1);
QCOMPARE(buttonMA->hovered(), true);
QCOMPARE(buttonHoveredSpy.count(), 1);
#if QT_CONFIG(cursor)
@@ -216,7 +216,7 @@ void tst_HoverHandler::mouseAreaAndUnderlyingHoverHandler()
QTest::mouseMove(window, rightOfButton);
QCOMPARE(topSidebarHH->isHovered(), true);
- QCOMPARE(sidebarHoveredSpy.count(), 3);
+ QCOMPARE(sidebarHoveredSpy.count(), 1);
QCOMPARE(buttonMA->hovered(), false);
QCOMPARE(buttonHoveredSpy.count(), 2);
#if QT_CONFIG(cursor)
@@ -225,7 +225,7 @@ void tst_HoverHandler::mouseAreaAndUnderlyingHoverHandler()
QTest::mouseMove(window, outOfSidebar);
QCOMPARE(topSidebarHH->isHovered(), false);
- QCOMPARE(sidebarHoveredSpy.count(), 4);
+ QCOMPARE(sidebarHoveredSpy.count(), 2);
QCOMPARE(buttonMA->hovered(), false);
QCOMPARE(buttonHoveredSpy.count(), 2);
#if QT_CONFIG(cursor)