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. Custom mouse pointer?

Custom mouse pointer?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlmouse pointer
5 Posts 3 Posters 3.4k 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.
  • P Offline
    P Offline
    pderocco
    wrote on last edited by pderocco
    #1

    I'd like to create a couple of non-standard mouse pointers, extra large ones that are easily visible when the window is projected on a screen, or captured to video, for demo purposes. I'd like a big arrow for the default cursor, and a big pointing finger when over an active control (which I construct out of a Rectangle and a MouseArea).

    I see a QCursor class in Qt, but no easy way to use it in QML. Since my app is statically linked with the Qt libraries, I'd be willing to patch the source to add a couple of cursor shapes, or perhaps replace a couple of existing shapes that I don't need, if I knew where they were in the code. Does that sound like the easiest approach? Or is there some way to associate a QCursor with a QtQuick control?

    If it matters, I only need this to work in Windows, since that's what I'd be using for demos.

    KillerSmathK 1 Reply Last reply
    0
    • P pderocco

      I'd like to create a couple of non-standard mouse pointers, extra large ones that are easily visible when the window is projected on a screen, or captured to video, for demo purposes. I'd like a big arrow for the default cursor, and a big pointing finger when over an active control (which I construct out of a Rectangle and a MouseArea).

      I see a QCursor class in Qt, but no easy way to use it in QML. Since my app is statically linked with the Qt libraries, I'd be willing to patch the source to add a couple of cursor shapes, or perhaps replace a couple of existing shapes that I don't need, if I knew where they were in the code. Does that sound like the easiest approach? Or is there some way to associate a QCursor with a QtQuick control?

      If it matters, I only need this to work in Windows, since that's what I'd be using for demos.

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @pderocco
      I not sure if QT has a native method to set a custom cursor from QML.
      Probably, you will need to create a custom QObject and forward it to QML to call setCursor function from C++.

      Something like that:

      MouseArea{
            anchors.fill: parent
            hoverEnabled: true
            onEntered:{
                 backend.setCursor(YourCustomCursor)
            }
            onExited:{
                 backend.setCursor(YourDefaultCursor)
            }
      }
      

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      P 1 Reply Last reply
      4
      • KillerSmathK KillerSmath

        @pderocco
        I not sure if QT has a native method to set a custom cursor from QML.
        Probably, you will need to create a custom QObject and forward it to QML to call setCursor function from C++.

        Something like that:

        MouseArea{
              anchors.fill: parent
              hoverEnabled: true
              onEntered:{
                   backend.setCursor(YourCustomCursor)
              }
              onExited:{
                   backend.setCursor(YourDefaultCursor)
              }
        }
        
        P Offline
        P Offline
        pderocco
        wrote on last edited by
        #3

        @KillerSmath The problem with that is that every object that responds to the mouse needs to have extra code added to it.

        I think the idea of replacing a couple of unneeded stock cursors would be the simplest to implement, until some later Qt version provides the ability to register new cursors at run-time. Does anyone know where, in the 227899 Qt source files, the stock cursors are found?

        J.HilkJ 1 Reply Last reply
        0
        • P pderocco

          @KillerSmath The problem with that is that every object that responds to the mouse needs to have extra code added to it.

          I think the idea of replacing a couple of unneeded stock cursors would be the simplest to implement, until some later Qt version provides the ability to register new cursors at run-time. Does anyone know where, in the 227899 Qt source files, the stock cursors are found?

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @pderocco said in Custom mouse pointer?:

          The problem with that is that every object that responds to the mouse needs to have extra code added to it.

          not necessarily because there is
          https://doc.qt.io/qt-5/qguiapplication.html#setOverrideCursor


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          P 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @pderocco said in Custom mouse pointer?:

            The problem with that is that every object that responds to the mouse needs to have extra code added to it.

            not necessarily because there is
            https://doc.qt.io/qt-5/qguiapplication.html#setOverrideCursor

            P Offline
            P Offline
            pderocco
            wrote on last edited by
            #5

            @J.Hilk My app is pretty simple, cursor-wise. It uses an arrow in the inactive areas, and a pointing finger on active controls. I want to replace them with really big versions, when doing demos that will be projected or captured to video, probably in response to a command line option. It seems to me that setOverrideCursor and restoreOverrideCursor could be called by onEntered and onExited signal handlers, but they'd have to be attached to every MouseArea in my program, which is a pretty significant impact. I wish there was a way, on startup, of redefining the cursors that are associated with the various enumeration constants, because the rest of the code would be untouched.

            But do those functions even work in QML? Or do they just apply to Qt widgets?

            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