python - 一些工具栏没有显示,也不能移动
问题描述
我正在尝试在 PyQt5 上构建一个 GUI。最近我试图添加一个工具栏。但是当我使用 MAC OS 时,保留的项目没有显示出来。工具栏也是静态的,我无法真正移动它们。
我尝试使用 stackoverflow Missing menuBar in PyQt5中提供的解决方案
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow,QAction
from PyQt5.QtGui import QIcon
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.title = "PyQt5 Tool Bars"
self.top = 100
self.left = 100
self.width = 680
self.height = 500
self.InitWindow()
def InitWindow(self):
#exitAct = QAction(QIcon('exit.png'), ' GoOut', self)
#exitAct.setShortcut('Ctrl+Q')
#exitAct.triggered.connect(self.CloseApp)
exitAct = QAction(QIcon('exit.png'), '&Exit', self)
print(exitAct.menuRole()) # It prints "1".
QAction::TextHeuristicRole
exitAct.setMenuRole(QAction.NoRole)
copyAct = QAction(QIcon('copy.png'), 'Copy', self)
copyAct.setShortcut('Ctrl+C')
pasteAct = QAction(QIcon('paste.png'), 'Paste', self)
pasteAct.setShortcut('Ctrl+V')
deleteAct = QAction(QIcon('del.png'), 'Delete', self)
deleteAct.setShortcut('Ctrl+D')
saveAct = QAction(QIcon('save.png'), 'Save', self)
saveAct.setShortcut('Ctrl+S')
self.toolbar = self.addToolBar('Toolbar')
self.toolbar.addAction(exitAct)
self.toolbar.addAction(copyAct)
self.toolbar.addAction(pasteAct)
self.toolbar.addAction(deleteAct)
self.toolbar.addAction(saveAct)
self.setWindowTitle(self.title)
self.setGeometry(self.top, self.left, self.width, self.height)
self.show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
我希望能看到所有的图标。
解决方案
推荐阅读
- asp.net - asp.net core - 将异常描述传递给客户端(例如 Angular)
- asp.net - Ajax 调用未将数组传递给控制器操作
- angular - 打开时Angular2 Ng日期时间选择器太大
- android - 如何停止在标签中延迟显示插页式广告?
- java - 如何接收短信?
- javascript - 从迭代器中获取当前值
- javascript - 从异步函数渲染反应本机孩子
- php - MySQL从一列计算整数值的总和并将结果存储在另一个表中
- java - 如何在 ROOTED 设备上录制 VOIP 通话?
- javascript - 如何在 php mysql 查询中获取 javascript 变量?