pyqt5 自定义菜单(1)

class PopMenu(QMenu):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.item1 = self.addAction('item1')
        self.item1.setShortcut(Qt.CTRL | Qt.Key_Q)
        self.addAction('item2')
        self.addSeparator()
        self.addAction('item3')
        self.subMenu = self.addMenu('menu1')
        self.subMenu.addAction('subitem1')
        self.subMenu.addAction('subitem2')
        self.triggered.connect(self._triggered)
    def _triggered(self, action): #出发点击,快捷键等信号
        print(action.text())
    def keyPressEvent(self, e): #按键事件
        if (e.modifiers() == Qt.ControlModifier) and e.key() == Qt.Key_Q: #设置组合键事件
            print('触发组合键')

 

posted @ 2018-01-30 17:48  我是外婆  阅读(1466)  评论(0编辑  收藏  举报