Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Change Mouse Cursor
QtWS25 Last Chance

Change Mouse Cursor

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 5 Posters 21.9k Views
  • 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 Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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
      0
      • B Offline
        B Offline
        bunjee
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          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
          0
          • F Offline
            F Offline
            franziss
            wrote on last edited by
            #5

            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
            0
            • B Offline
              B Offline
              bunjee
              wrote on last edited by
              #6

              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
              0
              • F Offline
                F Offline
                franziss
                wrote on last edited by
                #7

                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
                0
                • T Offline
                  T Offline
                  TonyR
                  wrote on last edited by
                  #8

                  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
                  0
                  • N Offline
                    N Offline
                    njeisecke
                    wrote on last edited by
                    #9

                    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
                    0
                    • T Offline
                      T Offline
                      TonyR
                      wrote on last edited by
                      #10

                      Many thanks Nils!
                      Very good and clear example

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved