0

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.

This is what I see

user6016731
  • 382
  • 5
  • 18
  • can you add a screenshot? – cmaureir Jan 31 '19 at 12:57
  • Be careful with the `NoRole` (This action should not be put into the application menu) for the `Exit` case, or that's the desire behavior? Also, when you execute the application, does it say anything on the terminal? I'm afraid the buttons are there, but maybe the PNG are missing. – cmaureir Jan 31 '19 at 13:14
  • I am accessing the pngs from the same location & how come 2 pngs appear as desired but the other 2 doesn't? – user6016731 Jan 31 '19 at 13:43

0 Answers0