Unsolved 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. It work correctly in all other cases.
In my app i have 1 main qWindow called
QWindow* mMainWindow;
and following code added to tray buttonmMenu->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. MethodmMainWindow->isActive()
return correcttrue
state when app is active andfalse
when it is hidden.But when I hide app using build-in in mac "cmd + h",
mMainWindow->isActive()
returntrue
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 ofQWindow
and callingwidget->activateWindow()
but it is not solution i can use in my case. -
Hi and welcome to devnet,
Which version of Qt are you using ?
On which version of macOS ?
Can you provide a minimal compilable example that shows that behaviour ? -
Which version of Qt are you using ? 5.15.0
On which version of macOS ? Mojave
Can you provide a minimal compilable example that shows that behaviour ?Here is quick example of the problem (mine tray is written in cpp, but i can see that problem also appear when using qml one).
Click
Hide
thenShow
and it work fine.
Use "cmd + h" thenShow
and it doesnt.import QtQuick 2.15 import QtQuick.Window 2.15 import Qt.labs.platform 1.1 Window { id: window visible: true width: 640 height: 480 SystemTrayIcon { visible: true menu: Menu { MenuItem { text: qsTr("Show") onTriggered: {window.show(); window.raise(); } } MenuItem { text: qsTr("Hide") onTriggered: window.hide() } } } }
After writing this example i have realised that if you call
Hide
after Window was hidden with Mac shortcut,Show
will work. (didn't realise sooner because my app has no Hide button)
So looks like i will just add to my show button extrahide()
call as a work-around to this bug and my code will looks like this.mMenu->addAction(createAction("Show", [=] { if (mMainWindow) { mMainWindow->hide(); mMainWindow->show(); mMainWindow->raise(); mMainWindow->requestActivate(); } }));
-
I currently do not know whether the CMD+H action provides any feedback to the application. Your workaround was what came to mind. Glad it is working.