Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Change cursor shape

    General and Desktop
    2
    12
    4410
    Loading More Posts
    • 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
      alecs26 last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • A
          alecs26 last edited by

          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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @alecs26 last edited by mrjj

            @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 Reply Quote 0
            • A
              alecs26 last edited by

              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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @alecs26 last edited by mrjj

                @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 Reply Quote 0
                • A
                  alecs26 last edited by

                  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 Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion last edited by mrjj

                    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 Reply Quote 0
                    • A
                      alecs26 last edited by

                      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 !

                      mrjj 1 Reply Last reply Reply Quote 1
                      • mrjj
                        mrjj Lifetime Qt Champion @alecs26 last edited by

                        @alecs26 said in Change cursor shape:

                        WindowTransparentForInput

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

                        1 Reply Last reply Reply Quote 0
                        • A
                          alecs26 last edited by

                          Yes, thank you for your help again !

                          mrjj 1 Reply Last reply Reply Quote 1
                          • mrjj
                            mrjj Lifetime Qt Champion @alecs26 last edited by

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

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post