I would like to know if it's possible to focus on my application even if it has lost focus?
My application is running a thread, and once I exit it, I would like to bring my window application to the front.
I've tried the following code, it works to focus on the widget I'd like to, but if you're on firefox, it will just flash once in taskbar, and don't focus :(
this->activateWindow();
this->show();
this->setFocus();
EDIT: This would do it, but I don't want my application 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.
解决方案
try
this->setWindowState(Qt::WindowActive);
it worked for me. (Qt 4.8, Windows 7, MinGW 4.4)
EDIT: I've since found that this usually only works if the window is currently minimized. so if it is not working try adding
this->setWindowState(Qt::WindowMinimized);
before it.