qt移动焦点_Qt - 专注于失去焦点的应用程序?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值