Change cursor shape

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


  • Qt Champions 2017

    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

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

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


  • Qt Champions 2017

    @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
    but that is NOT a good idea if u plan to give app to other people :)

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



  • Qt Champions 2017

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

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

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

  • Qt Champions 2017

    Its a function call from a Widget

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

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

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

  • Qt Champions 2017

    @alecs26 said in Change cursor shape:


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

  • Yes, thank you for your help again !

  • Qt Champions 2017

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.