PYQT5(十一)实现右键菜单
2019-01-01 本文已影响488人
弗兰克万岁
窗体绑定右键事件
self.window.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.window.customContextMenuRequested.connect(self.rightMenuShow)
设置右键菜单事件,和后续的动作
def rightMenuShow(self):
try:
self.contextMenu = QMenu()
self.actionA = self.contextMenu.addAction(u'动作a')
self.contextMenu.popup(QCursor.pos()) # 2菜单显示的位置
self.actionA.triggered.connect(self.actionHandler)
self.contextMenu.show()
except Exception as e:
print(e)
def actionHandler(self):
print('action')