PyQt6: Popup QMainWindow sometimes "missing" clicks even if opened and activated

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 is unresponsive even though it is 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.

I have been able to reproduce these issues on macOS 15 Sequoia and macOS 26 Tahoe, using a mouse (on a Mac Mini) and a trackpad (on a MacBook Air). In the latter case, the missed clicks tend to be more frequent if the “tap to click” setting is enabled on the trackpad.

I tried explicitly 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. Despite these attempted fixes, 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?

After further research, I finally discovered a fix. Basically, the menu bar extra app needs to open a window and keep it open in order for the popup to be properly focused when clicking on the menu bar extra icon. To fix the issue with my app, I’ve made this extra window invisible, and it’s now consistently receiving and acting on mouse clicks.