[solved] Raise Window to Front using "SwitchToThisWindow"

  • Hi guys and girls,

    I want the MainWindow to be pushed on top of the windows stack.
    As I understand an application shall not do this, that's why raise() and showNormal() won't do.

    My plan is to use the windows routine SwitchToThisWindow( HWND hWnd, BOOL fAltTab )

    What kills my plan is that the windows handle seems not to be accessible any longer in 5.x.
    I tried the way around via

    QPlatformNativeInterface* interfacep = QGuiApplication::platformNativeInterface();
    HWND handle = static_cast<HWND>(interfacep->nativeResourceForWindow(QByteArrayLiteral("handle"), window() ));
    SwitchToThisWindow( handle, (WINBOOL)false );

    But the window handle seems to be wrong, because some windows will be raised, but not the correct one (it is the same during one run each time the SwitchToThisWindow() is called, but when the program is restarted, it is randomly any window).

    Question A) is there maybe only a problem with the cast and the routine to get the window handle is wrong?

    Question B) is there a solution provided by the QT-API to switch the window to the top, so I can drop the windows specific SwitchToWindow() routine?

    Thanks so far...

  • ...sorry, was my fault...
    The windows handles are correct. When I set the bool "by alt-tab" to true, the correct window reacts.
    But that way the application blinks and comes not to the front. That's the same like showNormal(), so I didn't win anything...

    If anybody has an idea how to raise a window above all other windows I would appreciate it, but the initial question as I described it seems to be solved.

Log in to reply

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