Qt window on top of virtual keyboard



  • Hello,

    I have a Qt window that I want to stay on top of everything. I have done that with

    flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WindowTransparentForInput
    

    However, it does not stay on top of all windows. For instance, it does not stay over virtual keyboards (for instance the default windows osk keyboard, which is a keyboard on the screen).

    I have tried

    flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.WindowTransparentForInput| Qt.X11BypassWindowManagerHint
    

    but it does not work either.

    There seems to have some anwers in the following forum but I don't understand where to put these code lines and how.
    http://stackoverflow.com/questions/3316350/active-windows-in-windows-and-qwidgetactivatewindow

    I am on Windows10 with Qt5 QML Controls 2.

    Thank you very much for your help !

    Alex


  • Qt Champions 2016

    Hi
    I do not think u can be on top of osk.exe
    At least not via Qt . Maybe with tricks or timer
    Also not even OTHER OSK apps can be over it so it seems really special :)

    https://blogs.msdn.microsoft.com/oldnewthing/20110310-00/?p=11253

    Can i ask, what is the use case?



  • Thank you for your answer.

    I have a circle following the mouse but when I get over the osk keyboard it gets under the keyboard.

    However it get under other virtual keyboard as well so I am pretty sure there is a way to get "more on top" that I am now.
    There seems to have some anwers in the following forum but I don't understand where to put these code lines and how.
    http://stackoverflow.com/questions/3316350/active-windows-in-windows-and-qwidgetactivatewindow

    Thank you !

    Alex


  • Qt Champions 2016

    @alecs26

    Well i use a tool
    https://www.savardsoftware.com/turbotop/
    to make my command prompt stay on top.

    Even if its on top of all else. Not the osk.

    So i doubt that
    AllowSetForegroundWindow(ASF_ANY);
    SetForegroundWindow();
    can fix it.

    To call them, you must include windows.h
    and maybe link to some dll. (user32)
    which dll is shown in MS docs.



  • Perfect, thank you.

    I would still like to try AllowSetForegroundWindow(ASF_ANY); and SetForegroundWindow();
    So I guess I should call them in my main.cpp where I create the window ? I have:
    QQmlComponent componentmain(&engine,QUrl(QStringLiteral("qrc:/main.qml")));
    otherfunctions.objectmain=componentmain.create();

    I can then just type:
    AllowSetForegroundWindow(ASF_ANY);
    SetForegroundWindow();

    and it would apply to all windows ?
    Or can I do this in the window QML code ?

    Thank you !


  • Qt Champions 2016

    @alecs26

    Hi
    Im pretty sure you cannot call native api from QML
    but in main.cpp should be fine.

    Just tried with
    AllowSetForegroundWindow(ASFW_ANY );
    SetForegroundWindow((HWND)this->winId());

    for a mainwindow and its still not over OSK

    Maybe other will have a hint :)



  • @mrjj thank you for your answer.
    Just a small last thing. I tried the following code but I get an error for "SetForegroundWindow" :
    error: invalid use of 'this' in non-member function SetForegroundWindow((HWND)this->winId());
    I think it's a basic thing but I don't know what to do :(

    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
    
        QQmlComponent componentmain(&engine,QUrl(QStringLiteral("qrc:/main.qml")));
        QObject *objectmain;
        objectmain=componentmain.create();
            
        AllowSetForegroundWindow(ASFW_ANY);
        SetForegroundWindow((HWND)this->winId());
        
        return app.exec();
    }
    

    Thanks !

    Alex


  • Lifetime Qt Champion

    Hi,

    Because this is the current instance of a class with the methods of said class.

    If you want to get a WinID, you have to get the one from you application main window.



  • @SGaist I am very sorry for this basic question but from the following code, how can I get the WinId ?
    I tried objectmain.WinId and componentmain.WinId but neither worked.

    Thank you so much !

    Alex

    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
    
        QQmlComponent componentmain(&engine,QUrl(QStringLiteral("qrc:/main.qml")));
        QObject *objectmain;
        objectmain=componentmain.create();
            
        AllowSetForegroundWindow(ASFW_ANY);
        SetForegroundWindow((HWND)this->winId());
        
        return app.exec();
    }
    

  • Moderators

    @alecs26 You cannot use this outside a class (C++ basics). As @SGaist already said you need to use your main window instead of this.


Log in to reply
 

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