diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-06-29 12:07:33 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-06-30 14:32:57 +0200 |
commit | a81c111dd056efbd37b6267871367f3d975a1078 (patch) | |
tree | c3c410502ef2c2bc6a0ba0b18f6a29d433bea416 | |
parent | 1686104675b66fff6c0196b812312825913e8755 (diff) |
Change the cursor within HoverHandler.margin
The visual cursor feedback was inconsistent with the hovered property
when a margin is set.
Amends 1c44804600ad3dbeb60d1f5209ce9cf937d30ab3
Fixes: QTBUG-85303
Task-number: QTBUG-68073
Change-Id: I25506baecaecbd6450a0e95786f103024b46b1b8
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit b1493678fc295765ce93e565c5194e860e746436)
3 files changed, 82 insertions, 7 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 1b7315688b..906d59e6d3 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -3138,15 +3138,19 @@ QPair<QQuickItem*, QQuickPointerHandler*> QQuickWindowPrivate::findCursorItemAnd if (ret.first) return ret; } - if (itemPrivate->hasCursor || itemPrivate->hasCursorHandler) { - QPointF p = item->mapFromScene(scenePos); - if (!item->contains(p)) - return {nullptr, nullptr}; - if (itemPrivate->hasCursorHandler) { - if (auto handler = itemPrivate->effectiveCursorHandler()) + if (itemPrivate->hasCursorHandler) { + if (auto handler = itemPrivate->effectiveCursorHandler()) { + QQuickPointerEvent *pointerEvent = pointerEventInstance(QQuickPointerDevice::genericMouseDevice(), QEvent::MouseMove); + pointerEvent->point(0)->reset(Qt::TouchPointMoved, scenePos, quint64(1) << 24 /* mouse has device ID 1 */, 0); + pointerEvent->point(0)->setAccepted(true); + pointerEvent->localize(item); + if (handler->parentContains(pointerEvent->point(0))) return {item, handler}; } - if (itemPrivate->hasCursor) + } + if (itemPrivate->hasCursor) { + QPointF p = item->mapFromScene(scenePos); + if (item->contains(p)) return {item, nullptr}; } } diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverMargin.qml b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverMargin.qml new file mode 100644 index 0000000000..908b200c36 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverMargin.qml @@ -0,0 +1,20 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 + +Item { + visible: true + width: 200 + height: 200 + + Rectangle { + anchors.centerIn: parent + width: 50 + height: 50 + color: hh.hovered ? "tomato" : "wheat" + HoverHandler { + id: hh + margin: 20 + cursorShape: Qt.OpenHandCursor + } + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index 61f2752dd2..11a5393390 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -61,6 +61,7 @@ private slots: void mouseAreaAndUnderlyingHoverHandler(); void hoverHandlerAndUnderlyingMouseArea(); void movingItemWithHoverHandler(); + void margin(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); @@ -312,6 +313,56 @@ void tst_HoverHandler::movingItemWithHoverHandler() QTRY_COMPARE(paddleHH->isHovered(), false); } +void tst_HoverHandler::margin() // QTBUG-85303 +{ + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "hoverMargin.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem * item = window->rootObject()->findChild<QQuickItem *>(); + QVERIFY(item); + QQuickHoverHandler *hh = item->findChild<QQuickHoverHandler *>(); + QVERIFY(hh); + + QPoint itemCenter(item->mapToScene(QPointF(item->width() / 2, item->height() / 2)).toPoint()); + QPoint leftMargin = itemCenter - QPoint(35, 35); + QSignalSpy hoveredSpy(hh, SIGNAL(hoveredChanged())); + + QTest::mouseMove(window, {10, 10}); + QCOMPARE(hh->isHovered(), false); + QCOMPARE(hoveredSpy.count(), 0); +#if QT_CONFIG(cursor) + QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); +#endif + + QTest::mouseMove(window, leftMargin); + QCOMPARE(hh->isHovered(), true); + QCOMPARE(hoveredSpy.count(), 1); +#if QT_CONFIG(cursor) + QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); +#endif + + QTest::mouseMove(window, itemCenter); + QCOMPARE(hh->isHovered(), true); + QCOMPARE(hoveredSpy.count(), 1); +#if QT_CONFIG(cursor) + QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); +#endif + + QTest::mouseMove(window, leftMargin); + QCOMPARE(hh->isHovered(), true); +// QCOMPARE(hoveredSpy.count(), 1); +#if QT_CONFIG(cursor) + QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); +#endif + + QTest::mouseMove(window, {10, 10}); + QCOMPARE(hh->isHovered(), false); +// QCOMPARE(hoveredSpy.count(), 2); +#if QT_CONFIG(cursor) + QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); +#endif +} + QTEST_MAIN(tst_HoverHandler) #include "tst_qquickhoverhandler.moc" |