Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Custom mouse pointer?



  • 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.



  • @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)
          }
    }
    


  • @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?


  • Moderators

    @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



  • @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?


Log in to reply