QML Focus and handling hide command on MacOS Catalina
-
Hello,
I am having a problem working out a solution to the following problem.
Here is a simplified version of the app showing hiding/showing mechanism:(QT 6.2.4)
import QtQuick import QtQuick.Controls import Qt.labs.platform ApplicationWindow { id: appWindow visible: true width: 640 height: 480 title: qsTr("Hello World") function showWindow() { show() raise() requestActivate() } function hideWindow() { hide() } SystemTrayIcon { visible: true iconSource: "qrc:/images/tray-icon.png" menu: Menu { id: trayMenu MenuItem { text: qsTr("Show") onTriggered: { appWindow.showWindow() } } MenuItem { text: qsTr("Hide") onTriggered: { appWindow.hideWindow() } } } onActivated: function(reason) { /// bring appWindow to the front on mouse right click if (reason === SystemTrayIcon.Context || reason === SystemTrayIcon.DoubleClick) { appWindow.showWindow() } } } }
When I am doing hide -> show using tray icon menu options (left click on the tray icon to get the menu dropdown) window is correctly hiding and showing itself and also correctly handling OS hide event (
Ctrl+H
).
It works differently when instead of hiding it using hide from system tray I submitCtrl+H
and then click the right mouse button on the tray icon (invokingappWindow.showWindow()
). After that window is brought to the front and shown but nextCtrl+H
will not hide it anymore.Adding
modality: Qt.ApplicationModal
to the appWindow solves this problem since now it will be the only window that handles keystrokes and inputs but this will disable access toSystemTrayIcon
when the window is not hidden.From some testing, this seems to be a Catalina-specific bug because it works fine in the latter OS versions.
I am looking at least for some workaround to this problem.