From: Frederik Gladhorn Date: Fri, 26 Apr 2013 14:18:54 +0000 (+0200) Subject: Fix hover after press event X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d054755e9e452df05fb590510d25bf4167b97af7;p=konrad%2Fqtdeclarative.git Fix hover after press event When a mouse press event was rejected, we would unconditionally cancel the hover and claim that the mouse is not contained any more. Instead check if the mouse left and only then cancel the hover state. Task-number: QTBUG-30783 Change-Id: I5fac6f3a1f2807ef03e07982c603492d40d2a249 Reviewed-by: Florian Boucault Reviewed-by: Alan Alpert --- diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 324331f..a878658 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -954,7 +954,8 @@ void QQuickMouseArea::ungrabMouse() emit canceled(); emit pressedChanged(); emit pressedButtonsChanged(); - if (d->hovered) { + + if (d->hovered && !isUnderMouse()) { d->hovered = false; emit hoveredChanged(); } diff --git a/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml b/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml new file mode 100644 index 0000000..69ec8fb --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 + +Item { + width: 500 + height: 500 + + Rectangle { + width: 300 + height: 300 + color: "grey" + x: 100 + y: 100 + + MouseArea { + id: mouseArea + objectName: "mouseArea" + anchors.fill: parent + hoverEnabled: true + onPressed: mouse.accepted = false + //onContainsMouseChanged: print("containsMouse changed =", containsMouse) + + Rectangle { + visible: parent.containsMouse + color: "red" + width: 10; height: 10 + } + } + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index a959a60..a582c62 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -78,6 +78,7 @@ private slots: void hoverPosition(); void hoverPropagation(); void hoverVisible(); + void hoverAfterPress(); void disableAfterPress(); void onWheel(); void transformedMouseArea_data(); @@ -1007,6 +1008,33 @@ void tst_QQuickMouseArea::hoverVisible() delete window; } +void tst_QQuickMouseArea::hoverAfterPress() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("hoverAfterPress.qml")); + + QQuickItem *root = window->rootObject(); + QVERIFY(root != 0); + + QQuickMouseArea *mouseArea = window->rootObject()->findChild("mouseArea"); + QVERIFY(mouseArea != 0); + QTest::mouseMove(window, QPoint(22,33)); + QCOMPARE(mouseArea->hovered(), false); + QTest::mouseMove(window, QPoint(200,200)); + QCOMPARE(mouseArea->hovered(), true); + QTest::mouseMove(window, QPoint(22,33)); + QCOMPARE(mouseArea->hovered(), false); + QTest::mouseMove(window, QPoint(200,200)); + QCOMPARE(mouseArea->hovered(), true); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); + QCOMPARE(mouseArea->hovered(), true); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); + QCOMPARE(mouseArea->hovered(), true); + QTest::mouseMove(window, QPoint(22,33)); + QCOMPARE(mouseArea->hovered(), false); + delete window; +} + void tst_QQuickMouseArea::disableAfterPress() { QQuickView *window = createView();