1

I have an issue that I cannot raise my app Window when it got hidden with MacOS shortcut. It work correctly in all other cases.

In my app i have 1 main qWindow called 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. Method mMainWindow->isActive() return correct true state when app is active and false when it is hidden.

But when I hide app using build-in in mac "cmd + h", mMainWindow->isActive() return true regardless if app app is hidden or not. Calling my action item does nothing, mMainWindow stay all the time hidden.

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.

1 Answers1

0

I have discovered that if you call hide() before calling show(), show() will behaving correctly.

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.

  • Instead of hiding first (which could definitely result in window flickering on some platforms), have you tried other `show...` functions? – rubenvb Oct 14 '20 at 11:46
  • from qt doc for show() `This is equivalent to calling showFullScreen(), showMaximized(), or showNormal(), depending on the platform's default behavior for the window type and flags.` So it is same thing but with adding a flag with type of window. Yes i have tried manipulating flags. The issue is that `QWindow` "think" it is already active so it does nothing. Clearly some kind of qt bug. – Łukasz Szczesiak Oct 15 '20 at 13:33