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. Change cursor shape
QtWS25 Last Chance

Change cursor shape

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 5.3k 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.
  • A Offline
    A Offline
    alecs26
    wrote on last edited by
    #1

    Hello,

    I want to change the shape of the cursor. I can achieve this with cursorShape: Qt.OpenHandCursor. However, I want to change the shape not only when the cursor is over my application window but for the whole desktop.

    One possible way to do that is to extend my application window to full screen while setting transparency (but then I can't click on the desktop).

    1. Is there other simpler methodes 2) is it possible to click through my transparent window ?

    I am working on Windows with QML Controls2.

    Thank you very much for your help !

    Alex

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      The cursor is controlled by window so unless you override it for all
      applications, then the design is that custom cursor are just shown in/over the app.

      • is it possible to click through my transparent window ?

      Well there is
      widget->setAttribute(Qt::WA_TransparentForMouseEvents)

      Not tried with top level widget like the main window.
      Im not sure the clicks will reach the desktop.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alecs26
        wrote on last edited by
        #3

        Thank you very much for the information.
        Qt::WA_TransparentForMouseEvents indeed seems the best way to do this.

        I was however unable to set this attributes to the main Application Window. Any idea ?

        Thank you very much,

        Alex

        mrjjM 1 Reply Last reply
        0
        • A alecs26

          Thank you very much for the information.
          Qt::WA_TransparentForMouseEvents indeed seems the best way to do this.

          I was however unable to set this attributes to the main Application Window. Any idea ?

          Thank you very much,

          Alex

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @alecs26 said in Change cursor shape:

          I was however unable to set this attributes to the main Application Window. Any idea ?

          I guess it wont work with top level widgets then.
          Only when inside the app,( child win) so
          it wont work for allowing to click to desktop.

          If only for personal use, you could use
          https://msdn.microsoft.com/en-us/library/windows/desktop/ms648395(v=vs.85).aspx
          but that is NOT a good idea if u plan to give app to other people :)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alecs26
            wrote on last edited by
            #5

            hmmmm perfect, thank you.

            I know its possible since I already saw a program able to change the cursor in real time (when the cursor is still, a circle around the cursor fills up).
            I highly doubt it was done by changing the Windows cursor. I think it is possible to click through the window, but I don't know how to apply this to the main application window.

            Thanks,

            Alex

            mrjjM 1 Reply Last reply
            0
            • A alecs26

              hmmmm perfect, thank you.

              I know its possible since I already saw a program able to change the cursor in real time (when the cursor is still, a circle around the cursor fills up).
              I highly doubt it was done by changing the Windows cursor. I think it is possible to click through the window, but I don't know how to apply this to the main application window.

              Thanks,

              Alex

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @alecs26
              Well using native calls. all is possible :)
              I think click though can be be made with
              WS_EX_TRANSPARENT

              http://stackoverflow.com/questions/987019/qt-top-level-widget-with-keyboard-and-mouse-event-transparency/4930925#4930925

              Im not sure if possible in Qt directly. WA_TransparentForMouseEvents seems NOT to work
              outside the process. ( the app)

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alecs26
                wrote on last edited by
                #7

                That seems promising, thank you !

                I am starting with this and I have a stupid question.
                I tried the following in the main function of my .cpp

                    HWND hwnd = (HWND) winId();
                    LONG styles = GetWindowLong(hwnd, GWL_EXSTYLE);
                    SetWindowLong(hwnd, GWL_EXSTYLE, styles | WS_EX_TRANSPARENT);
                

                but I get winId not found. I guess I should include some things but I don't know what...

                I also maybe found another way with:

                    Qt::WindowFlags flags = windowFlags();
                    setWindowFlags(windowFlags() | Qt::WindowTransparentForInput);
                

                However, I get --> windowFlags not found.
                I don't know what to include for this...

                Thank you so much again !

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  Hi
                  Its a function call from a Widget
                  http://doc.qt.io/qt-5/qwidget.html#winId

                  HWND hwnd = (HWND) mainwindow->winId();

                  You just need
                  #if _WIN32
                  #include <windows.h>
                  #endif

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alecs26
                    wrote on last edited by
                    #9

                    Thank you so much for your help.
                    The other way I found was to set this in the QML:
                    flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WindowTransparentForInput

                    Qt.WindowTransparentForInput is not in the options when you try to see the available options but it works when you type it...

                    Thank you for everything !

                    mrjjM 1 Reply Last reply
                    1
                    • A alecs26

                      Thank you so much for your help.
                      The other way I found was to set this in the QML:
                      flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WindowTransparentForInput

                      Qt.WindowTransparentForInput is not in the options when you try to see the available options but it works when you type it...

                      Thank you for everything !

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @alecs26 said in Change cursor shape:

                      WindowTransparentForInput

                      Super. So this works for a top level (main ) window ?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alecs26
                        wrote on last edited by
                        #11

                        Yes, thank you for your help again !

                        mrjjM 1 Reply Last reply
                        1
                        • A alecs26

                          Yes, thank you for your help again !

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @alecs26
                          Np. And thx for reporting back. Never seen WindowTransparentForInput
                          so that will be handy for other QML users.

                          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