Bring application to front - portable way
Radek last edited by Radek
First of all, here's my setup: Windows 7 - 64bits, Qt 5.2.0. (MSVC 2010, 32 bit), Qtcreator 3.0.0. Developped application based on QMainWindow.
I'm currently trying to figure out a Qt (portable) way of bringign my application back to front, when it receives a defined tcp message.(The tcp stuff works perfectly - yay!)
I know there are a few topics and answers around the internet and on QtForum, like this one:
Re: Bring window to front -> raise()
... but they're all old, and not working in my case.
I've tried lots of things and combinations of
raise(), activatewindow(), setWindowFlags(), show()and whatnot.
The only thing that partially worked was
setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint); show(); setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); show();
or other ways of writing it but I hit a problem with that because the window stays on top, as if you couldn't remove
So the workaround I found was call native Win32 API:
SetWindowPos((HWND)winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetWindowPos((HWND)winId(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
Then it works, my app is back to front, but not locked to front!
Kinda hacky you say? ... yes, and I dont't like it bc it's not portable.
Anyone would have a Qt solution?
Thx for your time and neurons.