1

问题

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

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))

即使右键单击我们也会得到激活原因 QSystemTrayIcon::Trigger

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

问题

我们如何区分 MacOS 系统托盘图标的左键单击和右键单击?

4

1 回答 1

0

QApplication.mouseButtons方法可用于获取鼠标按钮的当前状态:

def on_systray_activated(self, i_reason):
    buttons = QtWidgets.qApp.mouseButtons()
    if buttons & QtCore.Qt.RightButton:
        logging.debug('on_systray_activated: right-button')
于 2017-12-17T17:40:15.557 回答