Qt - Focus on an application that has lost focus?

I would like to know if it is possible to focus on my application, even if it has lost focus?

My application launches a thread, and as soon as I exit it, I would like to bring my windowed application to the forefront.
I tried the following code, it works to focus on the widget that I would like, but if you are in firefox, it just blinks once in the taskbar and does not focus :(

this->activateWindow(); this->show(); this->setFocus(); 

EDIT: That would do it, but I don't want my application to stay on top ... and if I remove the flag, it loses focus = /

 this->setWindowFlags(Qt::WindowStaysOnTopHint); this->activateWindow(); this->show(); this->setFocus(); 

Thank you in advance for your answers.

+4
source share
1 answer

to try

 this->setWindowState(Qt::WindowActive); 

it worked for me. (Qt 4.8, Windows 7, MinGW 4.4)

EDIT: Since then, I have found that this usually only works if the window is currently minimized. so if it doesn't work try adding

 this->setWindowState(Qt::WindowMinimized); 

before that.

0
source

All Articles