Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52158

No Qt Quick Items besides MouseArea have a default cursor shape set

    XMLWordPrintable

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:

      main.qml
      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"
                  }
              }
          }
      }
      
      main.cpp
      #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):

      main.qml
      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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes