diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2023-11-10 17:07:15 -0700 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2023-11-18 08:23:02 -0700 |
commit | cd7c5f94a0ed64c52d31998957134d099313932a (patch) | |
tree | cac7b87e6f50341d9d73ac329c44a9ab45ec02bd /tests/auto/quick/pointerhandlers/qquickhoverhandler | |
parent | 03d58031c7233e0579f463b9484af8227b0938fd (diff) |
Update cursor if frame-synchronous hover update discovers hover change
Also mark cursor as dirty and force update after shape change.
Done-with: Matthias Rauter <matthias.rauter@qt.io>
Fixes: QTBUG-53987
Fixes: QTBUG-90457
Task-number: QTBUG-54019
Pick-to: 6.5 6.6
Change-Id: I64d9f5d0a39dbf141a8e82bee824b47a8884139b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickhoverhandler')
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickhoverhandler/data/changingCursor.qml | 37 | ||||
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp | 29 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/changingCursor.qml b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/changingCursor.qml new file mode 100644 index 0000000000..75bfbf5c34 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/changingCursor.qml @@ -0,0 +1,37 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick 2.15 + + +Rectangle { + id: brownRect + objectName: "brownRect" + + width: 400 + height: 400 + + HoverHandler { + id: hh + cursorShape: parent.colorIndex == 0 ? + Qt.CrossCursor : + Qt.OpenHandCursor + } + + property list<color> colors: ["beige", "brown"] + property int colorIndex: 0 + + color: colors[colorIndex] + + Timer { + id: colorTimer + interval: 200 + running: true + repeat: true + + onTriggered: { + parent.colorIndex = (parent.colorIndex + 1) % parent.colors.length; + parent.color = parent.colors[parent.colorIndex]; + } + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index e488c0486f..85f1cbda57 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -48,6 +48,7 @@ private slots: void deviceCursor(); void addHandlerFromCpp(); void ensureHoverHandlerWorksWhenItemHasHoverDisabled(); + void changeCursor(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); @@ -671,6 +672,34 @@ void tst_HoverHandler::ensureHoverHandlerWorksWhenItemHasHoverDisabled() QCOMPARE(spy.size(), 2); } +void tst_HoverHandler::changeCursor() +{ + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "changingCursor.qml"); + QQuickView * window = windowPtr.data(); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickItem *item = window->findChild<QQuickItem *>("brownRect"); + QVERIFY(item); + QQuickHoverHandler *hh = item->findChild<QQuickHoverHandler *>(); + QVERIFY(hh); + + QPoint itemCenter(item->mapToScene(QPointF(item->width() / 2, item->height() / 2)).toPoint()); + QSignalSpy hoveredSpy(hh, SIGNAL(hoveredChanged())); + + QTest::mouseMove(window, itemCenter); + + QTRY_COMPARE(hoveredSpy.size(), 1); + +#if QT_CONFIG(cursor) + QTRY_COMPARE(window->cursor().shape(), Qt::CrossCursor); + QTRY_COMPARE(window->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(window->cursor().shape(), Qt::CrossCursor); + QTRY_COMPARE(window->cursor().shape(), Qt::OpenHandCursor); +#endif +} + QTEST_MAIN(tst_HoverHandler) #include "tst_qquickhoverhandler.moc" |