Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a cursor theme for an entire Qt application?
Forum Updated to NodeBB v4.3 + New Features

How to create a cursor theme for an entire Qt application?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Lachrymology
    wrote on last edited by
    #1

    Hi all,

    I want to achieve a full cursor theme for my application, but I'm stuck. If the cursor is over a QLineEdit I want my own IBeamCursor, if it's over a QSplitterHandle I want my own SizeHorCursor.

    Currently I know about QWidget::setCursor() and QGuiApplication::setOverrideCursor() but this doesn't helps at all.

    I've tried to create an event filter and install it to QApplication, but this doesn't help, because I need to detect QCursor::shape which isn't possible because I can't get a handle to any instance of QCursor.

    Next step was to install the event filter on QMainWindow and get the QWidget::cursor() instance from there to handle it, but this failed too, because it doesn't change it's type belonging to the underlaying widget for example to IBeamCursor on a QLineEdit.

    Next step was to install the event filter on the underlaying widgets itself, such as QLineEdit, QTextEdit, etc, too. This finally worked and I was able to change the cursor to the right shape. Nevertheless it doesn't work on combined widgets like QSpinBox (Arrow/IBeam), QSplitter(Arrow/SizeHor), etc.

    Can it be that hard to set a full cursor theme for an entire Qt Application without installing filters to every widget? I mean we are talking about Qt 5.9.3! .. or am I off the track?

    Kind regards,
    Mike

    raven-worxR 1 Reply Last reply
    0
    • L Lachrymology

      Hi all,

      I want to achieve a full cursor theme for my application, but I'm stuck. If the cursor is over a QLineEdit I want my own IBeamCursor, if it's over a QSplitterHandle I want my own SizeHorCursor.

      Currently I know about QWidget::setCursor() and QGuiApplication::setOverrideCursor() but this doesn't helps at all.

      I've tried to create an event filter and install it to QApplication, but this doesn't help, because I need to detect QCursor::shape which isn't possible because I can't get a handle to any instance of QCursor.

      Next step was to install the event filter on QMainWindow and get the QWidget::cursor() instance from there to handle it, but this failed too, because it doesn't change it's type belonging to the underlaying widget for example to IBeamCursor on a QLineEdit.

      Next step was to install the event filter on the underlaying widgets itself, such as QLineEdit, QTextEdit, etc, too. This finally worked and I was able to change the cursor to the right shape. Nevertheless it doesn't work on combined widgets like QSpinBox (Arrow/IBeam), QSplitter(Arrow/SizeHor), etc.

      Can it be that hard to set a full cursor theme for an entire Qt Application without installing filters to every widget? I mean we are talking about Qt 5.9.3! .. or am I off the track?

      Kind regards,
      Mike

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Lachrymology said in How to create a cursor theme for an entire Qt application?:

      I've tried to create an event filter and install it to QApplication, but this doesn't help, because I need to detect QCursor::shape which isn't possible because I can't get a handle to any instance of QCursor.

      sine you installed an event-filter you also receive the watched QObject which you can cast to a QWidget and access it's cursor.
      But depending on your application structure this might end up in bad performance.

      The best way would be subclass all your widgets where you want a different cursor shape in your application.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lachrymology
        wrote on last edited by
        #3

        Yeah, that's what I'm guessing, that it would end up in bad performance and the other way around to subcall all used widgets would be hell of a work.

        Another idea would be QStyle or QStyleSheet .. are they capable to solve my issue in any way?

        J.HilkJ 1 Reply Last reply
        0
        • L Lachrymology

          Yeah, that's what I'm guessing, that it would end up in bad performance and the other way around to subcall all used widgets would be hell of a work.

          Another idea would be QStyle or QStyleSheet .. are they capable to solve my issue in any way?

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

          @Lachrymology
          I imagen you should be able to subclass QCursor and overwrite the default constructor of QCursor(Qt::CursorShape shape) with one that uses your own Bitmaps?

          I haven't done that myself yet, so just an idea.


          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.

          raven-worxR 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Lachrymology
            I imagen you should be able to subclass QCursor and overwrite the default constructor of QCursor(Qt::CursorShape shape) with one that uses your own Bitmaps?

            I haven't done that myself yet, so just an idea.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @J.Hilk
            QCursor is already capable of displaying custom bitmaps/pixmaps.
            The problem here is how to quickly set the custom cursors for the whole application.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            J.HilkJ 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @J.Hilk
              QCursor is already capable of displaying custom bitmaps/pixmaps.
              The problem here is how to quickly set the custom cursors for the whole application.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @raven-worx said in How to create a cursor theme for an entire Qt application?:

              @J.Hilk
              QCursor is already capable of displaying custom bitmaps/pixmaps.
              The problem here is how to quickly set the custom cursors for the whole application.

              I read that from the docu, the issue, from what I understand, is that the op does not want to manually change the cursor via subclassing widgets.

              To set a cursor shape use QCursor::setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the Qt::CursorShape enum.
              

              Out of this I read that the standart curser, when he 'enters' a widgets is set via QCursor constructor and QCursorShape-enum.

              The idea was to hock into the standart constructor (the one via QCursorShape-enum), switch-case over the enum. Than either use call the base function or use the custom constructor for shapes the op has custom bitmaps for.


              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.

              raven-worxR 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @raven-worx said in How to create a cursor theme for an entire Qt application?:

                @J.Hilk
                QCursor is already capable of displaying custom bitmaps/pixmaps.
                The problem here is how to quickly set the custom cursors for the whole application.

                I read that from the docu, the issue, from what I understand, is that the op does not want to manually change the cursor via subclassing widgets.

                To set a cursor shape use QCursor::setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the Qt::CursorShape enum.
                

                Out of this I read that the standart curser, when he 'enters' a widgets is set via QCursor constructor and QCursorShape-enum.

                The idea was to hock into the standart constructor (the one via QCursorShape-enum), switch-case over the enum. Than either use call the base function or use the custom constructor for shapes the op has custom bitmaps for.

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @J.Hilk said in How to create a cursor theme for an entire Qt application?:

                The idea was to hock into the standart constructor (the one via QCursorShape-enum), switch-case over the enum. Than either use call the base function or use the custom constructor for shapes the op has custom bitmaps for.

                this only works by modifying the Qt source code.
                Despite the possible (i don't know if there will be) side effects.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                J.HilkJ 1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @J.Hilk said in How to create a cursor theme for an entire Qt application?:

                  The idea was to hock into the standart constructor (the one via QCursorShape-enum), switch-case over the enum. Than either use call the base function or use the custom constructor for shapes the op has custom bitmaps for.

                  this only works by modifying the Qt source code.
                  Despite the possible (i don't know if there will be) side effects.

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #8

                  @raven-worx are you sure? I assumed one could replace the default cursor with QGuiApplication::setOverrideCursor()

                  Edit: looking a bit deeper into QGuiApplication::setOverrideCursor(), it seems I was mistaken and one would have indeed have to replace the default Qt.Cursor via Sourcecode change.


                  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.

                  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