I’m building a macOS menu bar extra (a.k.a. system tray) app using PyQt6. When clicking the menu bar icon, a popup window appears, which is a QMainWindow with the Qt.WindowType.Popup window flag set.
I’m noticing sporadic issues where the popup window doesn't respond to clicks even though it's open. Sometimes, clicking on a QPushButton inside the popup, or an action on the QMenu, causes it to close abruptly without the clicked signal being invoked on the button or the triggered action on a menu item (i.e., clicks are sometimes being “missed”). The popup window contains a QTreeWidget which I’ve styled with QSS so that hovering over a QTreeWidgetItem will cause it to be highlighted; sometimes the highlight doesn’t appear, suggesting that the open popup window is ignoring user interaction. Switching between windows from other open applications and then clicking the menu bar icon for my app sometimes causes the issue to occur.
The issue is reproducible on macOS 15 Sequoia and macOS 26 Tahoe, using a mouse (on a Mac Mini) and a trackpad (on a MacBook Air). I'm using PyQt6 version 6.11.0, and Python 3.14.4. The app is distributed as a PyInstaller build, but I've noticed this issue sometimes occurring on my dev machine, where the app is executed directly from the Python interpreter.
I tried calling the activateWindow() method on the QMainWindow object for the popup window, as well as calling grabMouse() (and releaseMouse() in the overridden method closeEvent()). I also ensured that the widgets within the popup window have its self object passed to their constructors. But the issue is still occurring.
What should I be doing to ensure that the popup window is consistently capturing mouse input when it’s opened? What gotchas and caveats that I missed that could be causing this issue?