Qt - 专注于失去焦点的应用程序? [英] Qt - Focus on a application that has lost focus?

查看:1017
本文介绍了Qt - 专注于失去焦点的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序正在运行一个线程,一旦我退出它, ,我想把我的窗口应用程序的前面。

我已经尝试了下面的代码,它的工作重点是我想要的部件,但如果你在Firefox上,它($ p
$ b

  this-> activateWindow(); 
将在任务栏中闪烁一次this-> show();
this-> setFocus();

编辑:这样做,但我不希望我的应用程序停留在顶部...如果我删除该标志,它会失去焦点= / $ / B
$ b $ pre> this-> setWindowFlags(Qt :: WindowStaysOnTopHint);
this-> activateWindow();
this-> show();
this-> setFocus();

谢谢您的回答。解决方案



  this-> setWindowState(Qt :: div class =h2_lin>无线ndowActive); 

它对我有效。 (Qt 4.8,Windows 7,MinGW 4.4)编辑:我已经发现,这通常只有当窗口目前最小化才有效。所以如果它不工作尝试添加

  this-> setWindowState(Qt :: WindowMinimized); 

之前。


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.

这篇关于Qt - 专注于失去焦点的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆