PDA

View Full Version : Bring application window to front



St@n
3rd July 2009, 13:32
Hello.
I have a some problem: I need to bring a QT application main window to front. It should become on the top of all windows (active and topmost).

I send a special message to my application (e.g. WM_USER_BRING_TO_TOP) and get the main window HWND (through winId()).
After this, i tried BringWindowToTop(), SetActiveWindow(), SetForegroundWindow(), set window style to WS_EX_TOPMOST, set window position to HWND_TOPMOST, but it all did not brought window to top. The only thing i've got was a flashing window on the taskbar.

Can anyone help me to understand why? Can you suggest a decision?

Thanks.

wysota
3rd July 2009, 16:02
Use QWidget::raise() and QApplication::setActiveWindow().

St@n
3rd July 2009, 19:09
No..))) It's not just simple as you can imagine :) I tried this many times...

The message is sent from another application. The methods raise(), activateWindow(), ... does not works. The window is only flashing on the taskbar. They does not change z-order of window and doesn't bring it to front. Probably, it was because there were a topmost window on my desktop...But i believe, that the decision exists. :)

genessr
4th July 2009, 02:10
Try this, it works....:)


this->setWindowFlags(Qt::WindowStaysOnTopHint);

Tell me if your problem still not solved....

St@n
6th July 2009, 09:18
No :( Does not work.. I've tried setFocus() (with setFocusPolicy), QAppilcation::setActiveWindow(), activateWindow(), show(), but they have all no effect. :(

Only flashing on taskbar (((

I've tried SetWindowPos with HWND_TOPMOST flag. It brings window to top. But in this case there were a problem, that window became "always on top" FOREVER. I' could not remove this attribute. If i passed HWND_NOTOPMOST, window jumped to bottom.. under another opened window. But i need it stays only visually on top, and can be overlapped by other windows.

PS: There were no "always on top" windows on desktop.

nish
6th July 2009, 10:46
you said that the message is sent from another application? so are the two applications Qt applications? If yes then take a look at QtSingleApplication class (its a solution from troll). what they have done is that they send message to other application which is caught in some function(slot may be).

so the point is that somehow you land up in your application's function.. in that.. you can experiment with first setting the windowOnTop flast and then reseting. ..

i dont remeber QtSingleApplication code so this info may not be correct.

St@n
6th July 2009, 13:06
To Mr.Death: Yes. It was exactly what i need. Thank you. You were right, i have 2 Qt applications. I'll try to use this, but i am not sure, that QtSingleApplication solution is included in version 4.5.1, that used by company i am working in. But i'll try. thanks.
PS: Another suggestions will be investigated too..:)

wysota
6th July 2009, 13:26
You can always use the SendMessage() WinAPI call to deliver a custom message to another application and then you can catch that message there and use raise() and setActiveWindow() (or whatever other combination you find useful).

St@n
7th July 2009, 10:46
I have exactly such implementation with SendMessage() as you say.
But raise() and activateWindow() and many others WinAPI calls did not worked!

Yesterday, i have found the problem.
It used AllowSetForegroundWindow() call which made the raise() call work. I think it was because raise() is implemented through SetForegroundWindow() API.

Thanks to all.

wysota
7th July 2009, 11:11
I have exactly such implementation with SendMessage() as you say.
But raise() and activateWindow() and many others WinAPI calls did not worked!
How exactly did you call them?

St@n
16th July 2009, 09:43
mainDialog->activateWindow()
mainDialog->raise()

PS: Problem is resolved :)

nish
16th July 2009, 09:48
can u put some example code of how exactly u did it..?

pavanbarot
4th October 2011, 14:38
Try this it might be helps you.

this->stackUnder(parentWidget()); [this means is your QMainWindow]

Marceepoo
5th July 2019, 02:55
Try this it might be helps you.

this->stackUnder(parentWidget()); [this means is your QMainWindow]

I used the following code to make a PyQt4 window the topmost window and to bring it to the front (in front of all other windows) in a Windows 10 64 bit environment:

self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint )

# The following is drawn from: https://stackoverflow.com/questions/12118939/how-to-make-a-pyqt4-window-jump-to-the-front
# the following will remove minimized status
# and restore window with keeping maximized/normal state
self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)

# this will activate the window
self.activateWindow()