diff options
author | Oliver Dawes <olliedawes@gmail.com> | 2022-12-21 15:48:07 +0000 |
---|---|---|
committer | Oliver Dawes <olliedawes@gmail.com> | 2023-01-17 20:58:31 +0000 |
commit | 000df08653be46420298acae8e16f831056a85b7 (patch) | |
tree | d80e9bdb81f6082cc674b074545b8b9a4b94dc8c /tests/auto | |
parent | 1c6afffc9403a2610de952a434f7633c5761117a (diff) |
Fix masked MouseArea hovered state on visibility change
This fixes the issue where given two hoverable MouseAreas A & B where B
masks A, the `containsMouse` property of A will be incorrectly set to
true if the cursor is positioned above both A and B and the visibility
of A is toggled from true to false back to true.
This patch fixes the above issue by checking if the QQuickMouseArea is
marked as a hovered item in its windows QQuickDeliveryAgentPrivate(QDAP)
instance. If the QQuickMouseArea is masked by another QQuickMouseArea
then it will not be a in the QDAPs hovered items list and we skip
setting the hovered property on QQuickMouseArea, fixing the issue.
This patch also adds a test case to prevent future regressions.
Fixes: QTBUG-109567
Pick-to: 6.5 6.4
Change-Id: I5f024a097b56ef5e0836ca9f8ae547983a089b44
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml | 24 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 49 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml b/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml new file mode 100644 index 0000000000..35cfd4b7ef --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml @@ -0,0 +1,24 @@ +import QtQuick + +Rectangle { + width: 200 + height: 200 + visible: true + MouseArea { + id: mouseArea1 + objectName: "mouseArea1" + anchors.fill: parent + hoverEnabled: true + visible: true + } + + MouseArea { + id: mouseArea2 + objectName: "mouseArea2" + anchors.centerIn: mouseArea1 + width: 50 + height: 50 + hoverEnabled: true + visible: true + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index 0d1d64d50d..fa42ce9ac0 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -138,6 +138,7 @@ private slots: void settingHiddenInPressUngrabs(); void negativeZStackingOrder(); void containsMouseAndVisibility(); + void containsMouseAndVisibilityMasked(); void doubleClickToHide(); void releaseFirstTouchAfterSecond(); #if QT_CONFIG(tabletevent) @@ -2459,6 +2460,54 @@ void tst_QQuickMouseArea::containsMouseAndVisibility() QVERIFY(!mouseArea->hovered()); } +// QTBUG-109567 +void tst_QQuickMouseArea::containsMouseAndVisibilityMasked() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouseMasked.qml"))); + + QQuickMouseArea *mouseArea1 = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea1"); + QVERIFY(mouseArea1 != nullptr); + QVERIFY(mouseArea1->isVisible()); + + QQuickMouseArea *mouseArea2 = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea2"); + QVERIFY(mouseArea2 != nullptr); + QVERIFY(mouseArea2->isVisible()); + + QTest::mouseMove(&window, QPoint(window.width() / 2, window.height() / 2)); + + // Check that mouseArea" (i.e. the masking MouseArea) is the only hovered MouseArea. + QTRY_VERIFY(!mouseArea1->hovered()); + QTRY_VERIFY(mouseArea2->hovered()); + + // Toggle the visibility of the masked MouseArea (mouseArea1). + mouseArea1->setVisible(false); + QVERIFY(!mouseArea1->isVisible()); + + mouseArea1->setVisible(true); + QVERIFY(mouseArea1->isVisible()); + + // Check that the masked MouseArea is not now hovered depite being under the mouse after + // changing the visibility to visible. mouseArea2 should be the only hovered MouseArea still. + QTRY_VERIFY(!mouseArea1->hovered()); + QTRY_VERIFY(mouseArea2->hovered()); + + QTest::mouseMove(&window, QPoint(10, 10)); + + QTRY_VERIFY(mouseArea1->hovered()); + QTRY_VERIFY(!mouseArea2->hovered()); + + // Toggle the visibility of the masked MouseArea (mouseArea1). + mouseArea1->setVisible(false); + QVERIFY(!mouseArea1->isVisible()); + + mouseArea1->setVisible(true); + QVERIFY(mouseArea1->isVisible()); + + QTRY_VERIFY(mouseArea1->hovered()); + QTRY_VERIFY(!mouseArea2->hovered()); +} + // QTBUG-35995 and QTBUG-102158 void tst_QQuickMouseArea::doubleClickToHide() { |