Qt - Focus on a application that has lost focus?
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 advan开发者_如何学Cce 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.
精彩评论