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 !

    Alex


  • Qt Champions 2016

    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.



  • 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


  • Qt Champions 2016

    @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 :)



  • 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


  • Qt Champions 2016

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



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

    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



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

    @alecs26 said in Change cursor shape:

    WindowTransparentForInput

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



  • Yes, thank you for your help again !


  • Qt Champions 2016

    @alecs26
    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.