From 33e24224555efa58736e9724aba19d0fc873b7c1 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 2 Dec 2021 23:34:44 +0100 Subject: HoverHandler: allow cursorShape binding before parentItem is set When a HoverHandler is declared in a Window, the handler's bindings are evaluated before QQuickItemPrivate::data_append() is called to add the handler to the window's content item. So we need null pointer checks again (as we have for a lot of calls to parentItem() already). And to ensure that the declared cursorShape actually is shown, we need to check again in componentComplete(). And don't forget to call the parent class implementation whenever overriding any virtual function. Fixes: QTBUG-98717 Change-Id: Id0defac7a238df522e8eee69f71e83a3947560af Reviewed-by: Fabian Kosmale (cherry picked from commit 3e95a57dc1fb39b059b52e16fcce7b4262f88b61) Reviewed-by: Shawn Rutledge --- .../qquickhoverhandler/tst_qquickhoverhandler.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp') diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index 11a5393390..c3429456ae 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -62,6 +62,7 @@ private slots: void hoverHandlerAndUnderlyingMouseArea(); void movingItemWithHoverHandler(); void margin(); + void window(); private: void createView(QScopedPointer &window, const char *fileName); @@ -363,6 +364,28 @@ void tst_HoverHandler::margin() // QTBUG-85303 #endif } +void tst_HoverHandler::window() // QTBUG-98717 +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("windowCursorShape.qml")); + QScopedPointer window(qobject_cast(component.create())); + QVERIFY(!window.isNull()); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); +#if QT_CONFIG(cursor) + if (isPlatformWayland()) + QSKIP("Wayland: QCursor::setPos() doesn't work."); +#ifdef Q_OS_MACOS + QSKIP("macOS: QCursor::setPos() doesn't work (QTBUG-76312)."); +#endif + auto cursorPos = window->mapToGlobal(QPoint(100, 100)); + qCDebug(lcPointerTests) << "in window @" << window->position() << "setting cursor pos" << cursorPos; + QCursor::setPos(cursorPos); + QTRY_COMPARE(window->cursor().shape(), Qt::OpenHandCursor); +#endif +} + QTEST_MAIN(tst_HoverHandler) #include "tst_qquickhoverhandler.moc" -- cgit v1.2.3