I am trying to build a GUI on PyQt5. Recently I was trying to add a toolbar. But as I am using a MAC OS the reserved items are not showing up. Also the toolbars are static & I cannot really move them around.
I have tried using solution as provided in 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())
I expect to get to see all the icons.