在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上的系统托盘图标左键和右键?
答案 0 :(得分:0)
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')