如何用QSystemTrayIcon区分左键和右键

2024-05-23 20:52:42 发布

您现在位置:Python中文网/ 问答频道 /正文

问题

在MacOS上运行以下PyQt5代码时(Sierra 10.12.6)

self.tray_icon = QtWidgets.QSystemTrayIcon(QtGui.QIcon("icon/path"), self)
self.tray_icon.activated.connect(self.on_systray_activated)

[...]

def on_systray_activated(self, i_reason):
    logging.debug("entered on_systray_activated. i_reason = " + str(i_reason))

即使右键单击也会得到activation reasonQSystemTrayIcon::Trigger

在其他系统上(例如XFCE),当用户右键单击时,我们得到QSystemTrayIcon::Context

问题

在MacOS上,如何区分左键和右键单击systray图标?在


Tags: 代码selfonmacospyqt5sierraiconreason
1条回答
网友
1楼 · 发布于 2024-05-23 20:52:42

QApplication.mouseButtons方法可用于获取当前的state of the mouse buttons

def on_systray_activated(self, i_reason):
    buttons = QtWidgets.qApp.mouseButtons()
    if buttons & QtCore.Qt.RightButton:
        logging.debug('on_systray_activated: right-button')

相关问题 更多 >