[Solved: Working as Expected] Bringing the application window to the front of all other applications on desktop.
I have no idea if this discussion has another resolved thread or not, but I couldn't find a solution any where. My requirement is one of my Qt application listens to another using QLocalServer and on new connection it would bring itself to the front of all other applications on desktop. I have used the following code which works fine only if my application windows is minimized. But if my application window is behind any other windows, then it just flashes on the taskbar.
setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
Please reply the solution if anybody knows/redirect me to any specific thread which has the resolution.
I think "this":http://www.qtcentre.org/threads/22197-Bring-application-window-to-front could help you
Thanks Martin, but I have already visited this link. It didn't help. Also I don't want mix native APIs with Qt APIs. I am looking for a solution that can be done using only Qt functions.
I think it's an intentional restriction of the Windows API that applications cannot always "steal" focus. If the application icon "flashes" on the taskbar, it means that Windows just decided that the application is not allowed to steal focus right now and that the user can switch to that application as soon as he prefers...
However you can create a "top most" window, that will stay on top, regardless of whether it has focus or not.
@setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)@
Thanks MuldeR, but Qt::WindowStaysOnTopHint flag will always make the application to stay on the top always, which I don't want. I do not understand why there should be a restriction. VLC Media player is also developed using Qt, then how does it work for the similar scenario? Does it use the native windows API to do so? If it is so, then why can't Qt support a wrapper cross API for the same?
I am looking forward to getting some solution guys...
As said before, this is a restriction of the underlying Win32 API, which Qt unavoidably has to use (on Win32).
I think the docs are quite clear:
(See remarks section!)
bq. 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.
This is because otherwise multiple processes might try to "steal" focus at the same time, which would lead to the focus jumping between different applications all the time, making the system unusable!!!
BTW: I never noticed VLC Player brings itself to the foreground, while I'm working with other applications. But if you refer to the "notification" banner that pops up now and then, that's probably a "top most" window which they only show when needed (while the VLC Player "main window" certainly is NOT top-most).
It definitely is possible to have a "top most" child window without making your "main" window top-most too.
Thanks MuldeR. I got it now. It is quite clear now.