diff options
author | Santhosh Kumar <[email protected]> | 2023-02-08 09:54:48 +0100 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2023-02-09 09:05:46 +0000 |
commit | 2af8743aab51287ec914d25176ae0fc45202db32 (patch) | |
tree | f7c29ad53ba0af88e4f1c22ea0ce6bcb55ccf910 | |
parent | 31722ff2ff7490efefeb838b052512e5ae365f5f (diff) |
Fix mouse inside MouseArea (containsMouse) for press event
In MouseArea, containsMouse (mouse inside MouseArea) flag is enabled for
press event irrespective of whether its accepted or not. This creates
containsMouse to be enabled always for this corresponding item leaving
no option to reset.
To fix this issue, containsMouse flag is enabled only if the press
event is accepted for mouse handler.
Fixes: QTBUG-110594
Pick-to: 6.4 6.5
Change-Id: Ibb0e89529ccebc3063330c22b8b3501b2917d78f
Reviewed-by: Shawn Rutledge <[email protected]>
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp | 15 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index cc941e1c04..4d8059273f 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -1130,8 +1130,10 @@ void QQuickMouseArea::setHoverEnabled(bool h) \qmlproperty bool QtQuick::MouseArea::containsMouse This property holds whether the mouse is currently inside the mouse area. - \warning If hoverEnabled is false, containsMouse will only be valid + \warning If hoverEnabled is \c false, \c containsMouse will be \c true when the mouse is pressed while the mouse cursor is inside the MouseArea. + But if you set \c {mouse.accepted = false} in an \c onPressed handler, + \c containsMouse will remain \c false because the press was rejected. */ bool QQuickMouseArea::hovered() const { @@ -1241,6 +1243,8 @@ bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p, Qt::MouseEventS if (!me.isAccepted()) { d->pressed = Qt::NoButton; + if (!hoverEnabled()) + setHovered(false); } if (!oldPressed) { diff --git a/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml new file mode 100644 index 0000000000..d98ef85c55 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml @@ -0,0 +1,15 @@ +import QtQuick + +Rectangle { + width: 200 + height: 200 + visible: true + MouseArea { + id: mouseArea + objectName: "mouseArea" + anchors.fill: parent + hoverEnabled: false + onPressed: function(mouse) { mouse.accepted = false } + } +} + diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index fd2b442a63..0ee9904405 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -139,6 +139,7 @@ private slots: void negativeZStackingOrder(); void containsMouseAndVisibility(); void containsMouseAndVisibilityMasked(); + void containsMouseAndHoverDisabled(); void doubleClickToHide(); void releaseFirstTouchAfterSecond(); #if QT_CONFIG(tabletevent) @@ -2508,6 +2509,20 @@ void tst_QQuickMouseArea::containsMouseAndVisibilityMasked() QTRY_VERIFY(!mouseArea2->hovered()); } +// QTBUG-110594 +void tst_QQuickMouseArea::containsMouseAndHoverDisabled() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouseAndHoverDisabled.qml"))); + + QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea"); + QVERIFY(mouseArea != nullptr); + QVERIFY(!mouseArea->hoverEnabled()); + + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTRY_VERIFY(!mouseArea->hovered()); +} + // QTBUG-35995 and QTBUG-102158 void tst_QQuickMouseArea::doubleClickToHide() { |