QSystemTrayIcon cannot respond to middle click on win11
-
import sys from PySide6.QtGui import QIcon from PySide6.QtWidgets import QApplication, QSystemTrayIcon class sysTray(QSystemTrayIcon): def __init__(self, parent=None): super().__init__(parent) self.icon = QIcon("Meta.ico") self.setIcon(self.icon) self.activated.connect(self.on_tray_activated) self.show() def on_tray_activated(self, reason): print(reason) if __name__ == "__main__": app = QApplication(sys.argv) tray = sysTray() sys.exit(app.exec())
This is a simple example to create a system tray in windows with PySide6. However, when I middle click the tray, it outputs
ActivationReason.Trigger
rather thanActivationReason.MiddleClick
. Is there something I am missing or is this a problem in windows11? -
Hi and welcome to devnet,
Might be a silly question but are you sure your middle button is identified as such ?
-
@SGaist
I add en eventfilter to sysTray itself:import sys from PySide6.QtCore import QEvent, QObject from PySide6.QtGui import QAction, QIcon from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon class sysTray(QSystemTrayIcon): def __init__(self, parent=None): super().__init__(parent) self.installEventFilter(self) self.icon = QIcon("icon/meta_running.ico") self.setIcon(self.icon) self._toggle_action = QAction("toggle", self) self._tray_icon_menu = QMenu() self._tray_icon_menu.addAction(self._toggle_action) self.setContextMenu(self._tray_icon_menu) self.show() def eventFilter(self, watched: QObject, event: QEvent) -> bool: print(watched, event) return super().eventFilter(watched, event) if __name__ == "__main__": app = QApplication(sys.argv) tray = sysTray() sys.exit(app.exec())
When I click the tray it outputs nothing.
And when I right click and move mouse to the context menu it outputs something.<__main__.sysTray(0x2a07487c970) at 0x000002A075151380> <PySide6.QtCore.QEvent(QEvent::ChildAdded)> <__main__.sysTray(0x2a07487c970) at 0x000002A075151380> <PySide6.QtCore.QEvent(QEvent::StatusTip)>
I have tried QWidget and everything is OK in Windows 11. I have also tried QSystemTrayIcon in Arch Linux and it is also OK.
No idea what is wrong with it in Windows 11.
-
Can you try forcing the style of the application to windowsvista or fusion ?