简体   繁体   English

在 MacOS 上使用 cmd + h 隐藏时无法显示()QWindow

[英]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.

相关问题 cc无法处理stdlib.h时如何在macOS上安装Perl模块 - How to install perl modules on macos when cc can't handle stdlib.h 如何让 sublime 在 macOS 中显示隐藏文件? - How can I have sublime show hidden files in macOS? macOS llvm 再也找不到 stdio.h - macOS llvm can't find stdio.h anymore 构建时无法表示 macOS 崩溃日志/没有 dSYM 文件 - Can't symbolicate macOS crash log / no dSYM file when building 在macos中由launchctl脚本触发时无法导入Python模块 - Python module can't be imported when triggered by launchctl script in macos 我无法将MacPorts的/opt/local/include/ncurses.h导入到我的Swift项目中。 它与macos SDK / usr / include / curses.h冲突。 有什么提示吗? - I can't import MacPorts' /opt/local/include/ncurses.h into my Swift project. It conflicts with macos SDK /usr/include/ curses.h. Any hint? 无法获得自定义PyQt5小部件插件以显示在Qt设计器中(macos) - Can't get custom PyQt5 widget plugin to show up in Qt designer (macos) macOS - 我在提示时拒绝了位置服务,现在弹出窗口不再显示 - macOS - I denied location services when prompted, and now the pop up won't show again 无法在 macOS 上卸载 SDKMAN - Can't uninstall SDKMAN on macOS 无法在 macos 中激活 webdev - Can't activate webdev in macos
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM