2 回答
TA贡献1884条经验 获得超4个赞
# This worked on PyQt5 on macOS Big Sur (ver 11.6)
# it is the result on painful trial and error
# and reading the Qt Docs
def _createMenuBar(self):
menuBar = self.menuBar()
# File menu
fileMenu = menuBar.addMenu("File")
fileMenu.addAction("New")
save = QAction("Save",self)
save.setShortcut("Ctrl+S")
fileMenu.addAction(save)
quit = QAction("\0Quit",self)
quit.setShortcut("Ctrl+Q")
fileMenu.addAction(quit)
# Edit menu
editMenu = menuBar.addMenu("Edit")
editMenu.addAction("Copy")
editMenu.addAction("Paste")
# Help menu
helpMenu=menuBar.addMenu("Help")
helpMenu.addAction(self.helpContentAction)
helpMenu.addAction(self.aboutAction)
TA贡献1818条经验 获得超11个赞
这可能有助于 PyQt5.QtWidgets import QMenuBar
Mainmenu=self.menuBar();# 创建菜单栏小部件
Filemenu=Mainmenu.addMenu('file');#这将文件添加到菜单栏
Editmenu=Mainmenu.addMenu('Edit');#这将编辑添加到菜单栏
添加回答
举报