Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.0.0
-
None
Description
In my application, I have a custom QQuickItem that sets Qt::BlankCursor. When an item (e.g. a popup) is made visible above this custom item, the cursor from the custom item is still visible. The reason for this is explained in this change.
An example:
import QtQuick 2.6 import QtQuick.Window 2.0 import App 1.0 Window { width: 600 height: 400 visible: true Rectangle { anchors.fill: parent CustomItem { width: 200 height: 200 Rectangle { anchors.fill: parent color: "salmon" } } TextEdit { width: 100 height: 30 text: "I'm a TextEdit." Rectangle { anchors.fill: parent color: "transparent" border.color: "grey" } } } }
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickItem> #include <QCursor> #include <QQuickWindow> class CustomItem : public QQuickItem { public: CustomItem() { setCursor(QCursor(Qt::CrossCursor)); } }; int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qmlRegisterType<CustomItem>("App", 1, 0, "CustomItem"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); static_cast<QQuickWindow*>(engine.rootObjects().first())->setCursor(QCursor(Qt::ArrowCursor)); return app.exec(); }
If you use MouseArea instead, it works (because of the fix for QTBUG-33157):
import QtQuick 2.6 import QtQuick.Window 2.0 import App 1.0 Window { width: 600 height: 400 visible: true Rectangle { anchors.fill: parent CustomItem { width: 200 height: 200 Rectangle { anchors.fill: parent color: "salmon" } } MouseArea { width: 100 height: 30 Rectangle { anchors.fill: parent color: "transparent" border.color: "grey" } } } }
While this doesn't appear to have affected/bothered many users, the implications are quite bad, because the cursor for the standard Qt Quick items can only be set through private C++ API. The most sensible workaround that I can think of is to create an empty QQuickItem subclass that sets cursorShape to Qt::ArrowCursor, and then use that as the parent of any items that should show the default cursor.
Attachments
Issue Links
- relates to
-
QTBUG-33157 MouseArea with no cursor set does not override the cursor of a MouseArea beneath it
- Closed
-
QTBUG-50482 QtQuick TextInput and TextEdit should use an IBeam mouse cursor by default
- Closed
-
QTBUG-14769 Cursor shapes on desktop systems (windows, etc)
- Closed