Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Change Mouse Cursor

    QML and Qt Quick
    5
    10
    20534
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bunjee last edited by

      I'm trying to change the mouse cursor from QML.

      Update: Cleared the content of this post by miss clicking. Sorry about that.

      1 Reply Last reply Reply Quote 0
      • M
        mbrasser last edited by

        Hi,

        That's correct, there isn't currently a cursor property (this is tracked by "QTBUG-10642":http://bugreports.qt.nokia.com/browse/QTBUG-10642).

        In the above, I believe "this" actually refers to the global object -- try giving the rectangle an id and passing that to your function instead.

        Regards,
        Michael

        1 Reply Last reply Reply Quote 0
        • B
          bunjee last edited by

          Hello mbrasser,

          Updated my code to this:
          @Rectangle {
          id: toto
          Component.onCompleted:
          {
          wView.setItemCursor(toto);
          }
          }@

          It appears I'm still getting an invalid pointer. I also tried changing my function prototype to QDeclarativeItem but that does not work either.

          Any idea ?

          Thanks.

          B.A.

          1 Reply Last reply Reply Quote 0
          • M
            mbrasser last edited by

            What version of Qt are you using? There was a bug at one point with QObject-derived function parameters, which should now be fixed (though I'm not sure if the fix was in 4.7.1 or coming in 4.7.2). If this is the issue you are running into, changing the function declaration to take a QObject* may work around it for you.

            Regards,
            Michael

            1 Reply Last reply Reply Quote 0
            • F
              franziss last edited by

              Sorry, I am a newbie to qt. I am trying to change the mouse cursor, from the point cursor to stretch cursor, when the mouse is over a MouseArea. Is this possible? I have read the above posts, but I don't understand what is going on,

              Many thanks.

              1 Reply Last reply Reply Quote 0
              • B
                bunjee last edited by

                Hi Franziss,

                This is currently not possible with the QML MouseArea.

                You have to declare a QML QObject class with this function:

                @/* Q_INVOKABLE */ void WControllerView::setItemCursor(QGraphicsObject * object, const QString & shape)
                {
                if (object == NULL)
                {
                qWarning("WControllerView::setItemCursor invalid QGraphicsObject");
                return;
                }

                if (shape == "")
                {
                    object->unsetCursor();
                    return;
                }
                
                Qt::CursorShape cursor;
                
                if      (shape == "PointingHandCursor") cursor = Qt::PointingHandCursor;
                else if (shape == "ArrowCursor")        cursor = Qt::ArrowCursor;
                else if (shape == "IBeamCursor")        cursor = Qt::IBeamCursor;
                else if (shape == "BlankCursor")        cursor = Qt::BlankCursor;
                

                // Add your "stretch cursor" here
                else cursor = Qt::ArrowCursor;

                object->setCursor(cursor);
                

                }@

                Then call it from QML like this:

                @Rectangle {
                id: toto
                Component.onCompleted:
                {
                wView.setItemCursor(toto, "YourCursorShape");
                }
                }@

                1 Reply Last reply Reply Quote 0
                • F
                  franziss last edited by

                  Hi Bunjee,

                  Thank you very much for your code, it works! But I use slots instead of Q_INVOKABLE

                  Have a nice day!

                  1 Reply Last reply Reply Quote 0
                  • T
                    TonyR last edited by

                    Hi All
                    Many thanks for good idea.
                    But I try use this solution fot ListView delegate and got app crash. Have you any idea?
                    Sorry I newbie in Qt & QML

                    1 Reply Last reply Reply Quote 0
                    • N
                      njeisecke last edited by

                      You could use the example code here:

                      http://developer.qt.nokia.com/doc/qt-4.7/qml-mousearea.html

                      The Qt Quick Desktop components offer a very similar class, too.

                      Nils

                      1 Reply Last reply Reply Quote 0
                      • T
                        TonyR last edited by

                        Many thanks Nils!
                        Very good and clear example

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post