QSystemTrayIcon and window focus
-
Hi folks,
I just noticed that there is a different behaviour on Windows and macOS if you click the QSystemTrayIcon. My menu is update before it is drawn, so I connected the following slot to
QMenu::aboutToShow
.void updateAction() { QWidget* activeWidget = QApplication::activeWindow(); mCloseAction->setEnabled(activeWidget != nullptr); }
On macOS the active window is the last focused Window e.g. MainWindow as expected. On Windows (10) on the other hand
QApplication::activeWindow()
returns a nullptr. Why is the frontmost window not set to be the active window again like on macOS? As far as I understood it, clicking outside of your application lets you lose the focus and therefore you have no active window anymore. I was just wondering if it is recreating native behaviour or if it a bug.Best regards,
Victor -
Hi,
Which version of Qt are you using ?
Which version of macOS ?
Which version of Windows ?
Can you provide a minimal compilable example that shows the behaviour ? -
Oh sorry, here are the information:
Qt 5.15.1 (same on Qt 5.14.2)
MacBook Pro (16-inch, 2019)
macOS 10.15.6 (19G2021)
Windows 10 (Build 19041)Minimal example: https://ufile.io/gamjo6zy
- Start your application and click on any other opened window (or the desktop)
- Right click the system tray icon
The action now is enabled on macOS, but disabled on windows.
-
Sorry, I have lost track on this thread. Would it be possible to make the example available again ?
In the mean time, 5.15.2 was released, did you check with it ?