aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-02-12 17:11:47 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-12 22:19:25 +0000
commit4f2cc0d258244c05d5b5419ce98fdeebe847caf9 (patch)
treea227e22b7149ed14f0e87bd56b52baabe669faca /src
parent90d3d42d1be64556bb417d0dda6f3a37342c6767 (diff)
MouseArea: fix containsMouse behavior during visibility changes
QQuickItem returns whether it contains QGuiApplicationPrivate's lastCursorPosition. Since that position stores the coordinate last seen by Qt (the window border), it will always be within the window, and within an item that covers that part of the window's border. However, QQuickWindow stores the lastMousePosition as well, and resets that value when it receives a QEvent::Leave. We can use that to test whether the window that contains the item has seen a Leave event, in which case the item is definitely not under the mouse. Notes on the test: That we use QPointF() as the "reset" value leave the small possibility that the cursor might be at position 0,0 of the window (ie inside the window), and the QQuickItem there will not be under the mouse. We can't confirm this (through an expected failure test), as QTest::mouseMove interprets a QPoint(0, 0) as "center of the window". And since we can't simulate mouse moves outside a window's boundary using QTest::mouseMove, the test needs to explicitly synthesize a QEvent::Leave for the window. Fixes: QTBUG-87197 Change-Id: I04870d6e914092275d9d790312fc702fb99f2935 Done-with: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit ba1246c543118515ea244787f3d7f9c1133ccf0f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickitem.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 38e83e08ff..83964c4a3a 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -7415,6 +7415,12 @@ bool QQuickItem::isUnderMouse() const
if (!d->window)
return false;
+ // QQuickWindow handles QEvent::Leave to reset the lastMousePosition
+ // FIXME: Using QPointF() as the reset value means an item will not be
+ // under the mouse if the mouse is at 0,0 of the window.
+ if (QQuickWindowPrivate::get(d->window)->lastMousePosition == QPointF())
+ return false;
+
QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
return contains(mapFromScene(d->window->mapFromGlobal(cursorPos.toPoint())));
}