Important: Please read the Qt Code of Conduct -

Qt::WindowStaysOnTopHint related question

  • Hi All,
    I examined Qt::WindowStaysOnTopHint flag of widget via Examples\Qt-5.9.1\widgets\widgets\windowflags application.
    The window with such a flag stays always foreground even I click to the other, not mine, application.
    It looks very strange. I need the window to be always shown on the screen but only inside my application. Not on the top of web-browser, Skype, mail and all-all-all applications on my computer!
    Is there any way provided to achieve that?
    Thank you!

  • Lifetime Qt Champion

    That is what WindowStaysOnTopHint does when the OS supports it.
    You can use QDialog to open a window that will stay on top of mainwindow.
    At least when its modal.

    But what effect are you after ?

    There are also
    which allowed to be embedded into main app but also floated and become a windows on its on.
    Sort of like an old MDI app but with free windows.

  • Thanks for your answer.
    My application is an editor fundamentally (I mean UI) like Adobe Photoshop for example. It has working windows and auxiliary toolbars and panels.
    I want toolbars and panels be always foreground for working windows.

    It's so cool on Mac: Qt::Tool windows have foreground priority on Qt::Window windows.
    "On macOS, tool windows correspond to the Floating class of windows. This means that the window lives on a level above normal windows making it impossible to put a normal window on top of it. "
    I want to have the same on Windows!
    Qt::WindowStaysOnTopHint seems to do what I need, but my panels are ALWAYS stay on the screen for all applications. Who needs that?

    Now I try to set and clean WindowStaysOnTopHint on QEvent::ApplicationActivate and QEvent::ApplicationDeactivate but I have a lot of weird side effects.!0_1510642908415_panels.png

  • @Sofia
    The behaviour should already be what you desire under Windows, i.e. on top only of application window not other desktop windows. Show some of your code/window flags?

  • Actually official qt's example \Qt5.9.1\Examples\Qt-5.9.1\widgets\widgets\windowflags is enough.
    I'll try qt 5.9.2 now, but for 5.9.1 Qt::Window and Qt::WindowStaysOnTopHint chosen in "windowflags" example application make resulting window to stay on the screen in spite of current active program.

  • Qt support has helped me. Windows with WindowStaysOnTopHint really should always stay foreground on the screen. It's proper behaviour. So the following code made my goal:

    connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(doStaysOnTopFlagProcessing(Qt::ApplicationState)));

    void MyToolbar::doStaysOnTopFlagProcessing(Qt::ApplicationState s)
    //if (parentWidget()) return;
    if (s == Qt::ApplicationActive) {
    else {
    setWindowFlag(Qt::WindowStaysOnTopHint, false);
    lower(); // or hide()

Log in to reply