[英]Can't show() QWindow when it was hidden with cmd + h on MacOS
I have an issue that I cannot raise my app Window when it got hidden with MacOS shortcut.我有一个问题,当它被 MacOS 快捷方式隐藏时,我无法提升我的应用程序窗口。 It work correctly in all other cases.它在所有其他情况下都能正常工作。
In my app i have 1 main qWindow called QWindow* mMainWindow;
在我的应用程序中,我有 1 个主 qWindow,称为QWindow* mMainWindow;
and following code added to tray button并将以下代码添加到托盘按钮
mMenu->addAction(createAction("Show", [=] {
if (mMainWindow) {
mMainWindow->show();
mMainWindow->raise();
mMainWindow->requestActivate();
}
When I just use qt mMainWindow->hide()
and then raise it back, mMainWindow
works fine.当我只使用 qt mMainWindow->hide()
然后将其抬起时, mMainWindow
工作正常。 Method mMainWindow->isActive()
return correct true
state when app is active and false
when it is hidden.当应用程序处于活动状态时,方法mMainWindow->isActive()
返回正确的true
状态,当它隐藏时返回false
。
But when I hide app using build-in in mac "cmd + h", mMainWindow->isActive()
return true
regardless if app app is hidden or not.但是当我使用内置在 mac "cmd + h" 中隐藏应用程序时,无论应用程序应用程序是否隐藏, mMainWindow->isActive()
返回true
。 Calling my action item does nothing, mMainWindow
stay all the time hidden.调用我的操作项没有任何作用, mMainWindow
一直处于隐藏状态。
Is there any solution to fix this issue?是否有解决此问题的解决方案? I have seen people recommend using QWidget
instead of QWindow
and calling widget->activateWindow()
but it is not solution i can use in my case.我见过有人推荐使用QWidget
而不是QWindow
并调用QWindow
widget->activateWindow()
但这不是我可以使用的解决方案。
I have discovered that if you call hide()
before calling show()
, show()
will behaving correctly.我发现如果您在调用show()
之前调用hide()
show()
, show()
将正常运行。
Workaround to this problem is following此问题的解决方法如下
mMenu->addAction(createAction("Show", [=] {
if (mMainWindow) {
mMainWindow->hide();
mMainWindow->show();
mMainWindow->raise();
mMainWindow->requestActivate();
}
}));
there may be issue that when app is already on focus, and you click Show
it will, hide and show again, but it is acceptable problem in my case.当应用程序已经处于焦点时,可能会出现问题,并且您单击“ Show
,然后隐藏并再次显示,但在我的情况下这是可以接受的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.