qmenubar qt code example
Example 1: Qmenubar pyqt
menubar = self.menuBar() # create our menubar
file = menubar.addMenu("&File") # create a file menu
open = QAction("&Open", self) # create a QAction
open.setShortcut("Ctrl+O") # set a shortcut for it
file.addAction(open) # and add it to our menu
# create another one and add it again to our menu
save = QAction("&Save",self)
save.setShortcut("Ctrl+S")
file.addAction(save)
# and if you want to connect your QActions to our slots you can do it like:
open.triggered.connect(lambda: self.yourfunction())
Example 2: How to give a QMenuBar button an action?
self.action = QAction(self)
self.action.setText("Action")
self.menubar.addAction(self.action)
self.action.triggered.connect(self.function)