diff options
author | Paul Olav Tvete <[email protected]> | 2025-06-02 15:43:31 +0200 |
---|---|---|
committer | Paul Olav Tvete <[email protected]> | 2025-06-04 09:37:29 +0200 |
commit | f5140d62082e9b06e0ca6c8e2175b5836286f52e (patch) | |
tree | e8b534d2bc3de54d365407b4037eabd2e8c0b72d | |
parent | da9de7c13ea2c212d4762568f0e2318d23a96116 (diff) |
The hover event delivery logic is based on scenePosition, so the global
position has to be calculated. Using item.mapToGlobal(scenePosition)
will apply the item's position twice. This change first calculates
localPosition and then uses item.mapToGlobal(localPosition).
Fixes: QTBUG-134099
Pick-to: 6.10 6.9 6.8
Change-Id: I83f1382784300a1c73ab2b6f50e0288dcf99689b
Reviewed-by: Morten Johan Sørvig <[email protected]>
-rw-r--r-- | src/quick/util/qquickdeliveryagent.cpp | 12 | ||||
-rw-r--r-- | tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp | 34 |
2 files changed, 42 insertions, 4 deletions
diff --git a/src/quick/util/qquickdeliveryagent.cpp b/src/quick/util/qquickdeliveryagent.cpp index 9301f64204..1d4d5904bb 100644 --- a/src/quick/util/qquickdeliveryagent.cpp +++ b/src/quick/util/qquickdeliveryagent.cpp @@ -1072,13 +1072,17 @@ bool QQuickDeliveryAgentPrivate::sendHoverEvent(QEvent::Type type, QQuickItem *i { auto itemPrivate = QQuickItemPrivate::get(item); const auto transform = itemPrivate->windowToItemTransform(); - auto globalPos = item->mapToGlobal(scenePos); - QHoverEvent hoverEvent(type, scenePos, globalPos, transform.map(lastScenePos), modifiers); + + const auto localPos = transform.map(scenePos); + const auto globalPos = item->mapToGlobal(localPos); + const auto lastLocalPos = transform.map(lastScenePos); + const auto lastGlobalPos = item->mapToGlobal(lastLocalPos); + QHoverEvent hoverEvent(type, scenePos, globalPos, lastLocalPos, modifiers); hoverEvent.setTimestamp(timestamp); hoverEvent.setAccepted(true); QEventPoint &point = hoverEvent.point(0); - QMutableEventPoint::setPosition(point, transform.map(scenePos)); - QMutableEventPoint::setGlobalLastPosition(point, item->mapToGlobal(lastScenePos)); + QMutableEventPoint::setPosition(point, localPos); + QMutableEventPoint::setGlobalLastPosition(point, lastGlobalPos); hasFiltered.clear(); if (sendFilteredMouseEvent(&hoverEvent, item, item->parentItem())) diff --git a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp index 688959833f..d012bac274 100644 --- a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp +++ b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp @@ -48,6 +48,7 @@ struct HoverItem : public QQuickItem { hoverEnter = true; e->setAccepted(block); + globalHoverPosition = e->globalPosition(); } void hoverLeaveEvent(QHoverEvent *e) override @@ -56,9 +57,16 @@ struct HoverItem : public QQuickItem e->setAccepted(block); } + void mousePressEvent(QMouseEvent *e) override + { + globalMousePosition = e->globalPosition(); + } + bool hoverEnter = false; bool hoverLeave = false; bool block = false; + QPointF globalHoverPosition; + QPointF globalMousePosition; }; // A QQuick3DViewport simulator @@ -145,6 +153,7 @@ private slots: void clearItemsOnHoverLeave(); void deleteTargetOnPress(); void compoundControlsFocusInSubscene(); + void hoverEventGlobalPosition(); private: std::unique_ptr<QPointingDevice> touchscreen{QTest::createTouchDevice()}; @@ -675,6 +684,31 @@ void tst_qquickdeliveryagent::compoundControlsFocusInSubscene() QCOMPARE(QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->rootItem->scopedFocusItem(), spinboxFocusScope); } +void tst_qquickdeliveryagent::hoverEventGlobalPosition() +{ + QQuickWindow window; + window.resize(200, 200); + window.show(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + HoverItem child(window.contentItem()); + child.setAcceptHoverEvents(true); + child.setAcceptedMouseButtons(Qt::LeftButton); + child.setX(50); + child.setY(50); + child.setWidth(100); + child.setHeight(100); + + QTest::mouseMove(&window, QPoint(25, 25)); + QCOMPARE(child.hoverEnter, false); + + QPoint point(100, 100); + QTest::mouseMove(&window, point); + QCOMPARE(child.hoverEnter, true); + QTest::mousePress(&window, Qt::LeftButton, {}, point); + QCOMPARE(child.globalHoverPosition, child.globalMousePosition); +} + QTEST_MAIN(tst_qquickdeliveryagent) #include "tst_qquickdeliveryagent.moc" |