diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 3ebfa9d971..325989a5d6 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -198,6 +198,8 @@ void QQuickWindow::showEvent(QShowEvent *) void QQuickWindow::hideEvent(QHideEvent *) { Q_D(QQuickWindow); + if (auto da = d->deliveryAgentPrivate()) + da->handleWindowHidden(this); if (d->windowManager) d->windowManager->hide(this); } diff --git a/src/quick/util/qquickdeliveryagent.cpp b/src/quick/util/qquickdeliveryagent.cpp index 42e6cdeaeb..759b09f6b0 100644 --- a/src/quick/util/qquickdeliveryagent.cpp +++ b/src/quick/util/qquickdeliveryagent.cpp @@ -1321,6 +1321,13 @@ void QQuickDeliveryAgentPrivate::handleWindowDeactivate(QQuickWindow *win) } } +void QQuickDeliveryAgentPrivate::handleWindowHidden(QQuickWindow *win) +{ + qCDebug(lcFocus) << "hidden" << win->title(); + clearHover(); + lastMousePosition = QPointF(); +} + bool QQuickDeliveryAgentPrivate::allUpdatedPointsAccepted(const QPointerEvent *ev) { for (auto &point : ev->points()) { diff --git a/src/quick/util/qquickdeliveryagent_p_p.h b/src/quick/util/qquickdeliveryagent_p_p.h index 66db4bc88c..7852ad4673 100644 --- a/src/quick/util/qquickdeliveryagent_p_p.h +++ b/src/quick/util/qquickdeliveryagent_p_p.h @@ -131,6 +131,7 @@ public: void flushFrameSynchronousEvents(QQuickWindow *win); void deliverDelayedTouchEvent(); void handleWindowDeactivate(QQuickWindow *win); + void handleWindowHidden(QQuickWindow *win); // utility functions that used to be in QQuickPointerEvent et al. bool allUpdatedPointsAccepted(const QPointerEvent *ev); diff --git a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp index 7e6416b8e2..a0a1c66217 100644 --- a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp +++ b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp @@ -138,6 +138,8 @@ private slots: void hoverPropagation_nested_data(); void hoverPropagation_nested(); void hoverPropagation_siblings(); + void hoverEnterOnItemMove(); + void hoverEnterOnItemMoveAfterHide(); private: QScopedPointer touchDevice = QScopedPointer(QTest::createTouchDevice()); @@ -521,6 +523,65 @@ void tst_qquickdeliveryagent::hoverPropagation_siblings() QCOMPARE(sibling2.hoverEnter, true); } +void tst_qquickdeliveryagent::hoverEnterOnItemMove() +{ + QQuickWindow window; + auto deliveryAgent = QQuickWindowPrivate::get(&window)->deliveryAgentPrivate(); + window.resize(200, 200); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // start with the mouse in the bottom right + QTest::mouseMove(&window, QPoint(150, 150)); + + HoverItem hoverItem(window.contentItem()); + hoverItem.setAcceptHoverEvents(true); + hoverItem.setWidth(100); + hoverItem.setHeight(100); + + deliveryAgent->flushFrameSynchronousEvents(&window); + + QCOMPARE(hoverItem.hoverEnter, false); + + // move the item so the mouse is now inside where the mouse was + hoverItem.setX(100); + hoverItem.setY(100); + deliveryAgent->flushFrameSynchronousEvents(&window); + QCOMPARE(hoverItem.hoverEnter, true); +} + +void tst_qquickdeliveryagent::hoverEnterOnItemMoveAfterHide() +{ + QQuickWindow window; + auto deliveryAgent = QQuickWindowPrivate::get(&window)->deliveryAgentPrivate(); + window.resize(200, 200); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // start with the mouse in the bottom right + QTest::mouseMove(&window, QPoint(149, 149)); + + HoverItem hoverItem(window.contentItem()); + hoverItem.setAcceptHoverEvents(true); + hoverItem.setWidth(100); + hoverItem.setHeight(100); + + deliveryAgent->flushFrameSynchronousEvents(&window); + QCOMPARE(hoverItem.hoverEnter, false); + + window.hide(); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QCOMPARE(hoverItem.hoverEnter, false); + + // move the item so the mouse is now inside where the mouse was + hoverItem.setX(100); + hoverItem.setY(100); + deliveryAgent->flushFrameSynchronousEvents(&window); + QCOMPARE(hoverItem.hoverEnter, false); +} + QTEST_MAIN(tst_qquickdeliveryagent) #include "tst_qquickdeliveryagent.moc"