Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How bring to front on Windows?



  • I use :

        show(); //bring window to top on OSX
        raise(); //bring window from minimized state on OSX
        activateWindow(); //bring window to front/unminimize on windows
    

    but this is not enough - in Windows 10 only flicks application on system status bar. It is not possible on Windows 10?


  • Lifetime Qt Champion

    Hi
    Well in windows 10, there are rules.
    https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setforegroundwindow
    see the Remarks section
    so what you see might be this
    "An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user."


  • Moderators

    This is the default behavior on Windows and you should think twice before overriding it. It's extremely annoying when apps steal focus, especially if you're typing or have another full screen app opened at that time.

    That being said you can change this behavior for your app by calling

    #ifdef Q_OS_WIN //this is Windows specific code, not portable
        QWindowsWindowFunctions::setWindowActivationBehavior(QWindowsWindowFunctions::AlwaysActivateWindow);
    #endif
    

    this will cause activateWindow() to bring your app to front. You should put that in a platform ifdef, as this is Windows specific switch.

    I'll repeat that this is strictly against platform recommendations and you should not do that unless you have a very good reason and I have yet to see an app that really does.



  • This is annoing in most cases, but I am writing editor which has many tabs and one instance and should be called from TotalCommander/DoubleCommander etc.


  • Moderators

    @AndrzejB That sounds like even more reasons not to do it. An app should never assume how it is invoked - through explorer, another process, command line, service etc. It should be the caller (user, app, service or whatever) responsibility to activate the process it started, not the process itself.


Log in to reply