Qt World Summit: Register Today!

Always On Top without Steal Focus - Linux

  • In Windows, we are using the following to bring the application to the foreground and always on top without stealing focus from other applications:

    mainWindow->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);

    In Linux, when implementing the above, the application does not come to the foreground. If I call activateWindow(), then the window comes to the foreground but steals focus from other applications.

    Replacing Qt::Tool with Qt::X11BypassWindowManagerHint works without calling activateWindow() and does not steal focus but with an issue. In this scenario, if you open a new window which is underneath buttons in our application, the user cannot interact with the buttons. The OS window management believes the newly opened window is now on top and limits the users interaction with buttons in our application. If you move the newly opened window off to the side, you can once again interact with buttons in our application.

    I need a solution for putting our window always on top of other applications and not stealing focus in Linux OS. Full interaction with our application should still be allowed regardless if a new window is opened while our application is displayed.

  • Lifetime Qt Champion

    It depends on the actual windows manager.
    Which one are you using?

  • You're never going to be able to do that for linux as a whole. Linux doesn't have a set window manager. People can use whatever they like.

    You can plan for the big ones like Gnome, KDE, etc but in the end people can run whatever they want, even old things like fluxbox, englightenment, etc.

  • @mrjj In our environment we are using Gnome.

  • @manncleary
    Is https://stackoverflow.com/a/1022121/489865 ("Show window in Qt without stealing focus") helpful?


    This forces the window not to activate. Even with the Qt::WindowStaysOnTopHint flag

    I'm not sure it's what you want [have a feeling it does the opposite of what you want... :( ], but might be worth a read/experiment for the ideas there?

    Something like https://major.io/2015/07/06/allow-new-windows-to-steal-focus-in-gnome-3/ or https://superuser.com/questions/143044/how-to-prevent-new-windows-from-stealing-focus-in-gnome discusses GNOME behaviour and tweaking. There are a fair number of hits from Google: gnome focus stealing prevention

Log in to reply