PyQt5 中 addSeparator 的理解
PyQt5 中 addSeparator 的理解
QAction QMenu.addSeparator (self)
This convenience function creates a new separator action, i.e. an action with
QAction.isSeparator() returning true, and adds the new action to this menu's list of actions.
It returns the newly created action.
[email protected]:~/c_study/hw_idarling/qt_prj$ cat Qtsep1.py
#!/usr/bin/env python
# coding=utf-8
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
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('触发组合键')
if __name__ == "__main__":
app = QApplication(sys.argv)
demo = PopMenu()
demo.show()
sys.exit(app.exec_())
demo code 引用自 https://www.cnblogs.com/alplf123/p/8386340.html