no menu Qt 6.8.1 on mac
-
I compiled Qt 6.8.1 on Mac Mini m2 but I can't get a menubar to display.
This is what I get using this simplified code below.from PyQt6.QtWidgets import * from PyQt6.QtGui import * from PyQt6.QtCore import * class TestApp(QMainWindow): def __init__(self): super().__init__() self.setupUi() def setupUi(self): self.setObjectName("MainWindow") self.resize(400, 400) self.centralwidget = QWidget(self) self.centralwidget.setObjectName("centralwidget") self.setCentralWidget(self.centralwidget) self.grid_layout = QGridLayout() self.centralwidget.setLayout(self.grid_layout) self.label = QLabel("Test", self.centralwidget) self.grid_layout.addWidget(self.label, 0, 0, alignment=Qt.AlignmentFlag.AlignCenter) # Create actions self.actionAbout_Swing_Studio = QAction("About Swing Studio", self) # Create menu bar self.menubar = QMenuBar(self) self.menubar.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) self.setMenuBar(self.menubar) # Create menus self.menuSwing_Studio = QMenu("Swing Studio", self.menubar) self.menubar.addMenu(self.menuSwing_Studio) # Add actions to menus self.menuSwing_Studio.addAction(self.actionAbout_Swing_Studio) # Create status bar self.statusbar = QStatusBar(self) self.statusbar.showMessage("Ready") self.setStatusBar(self.statusbar) if __name__ == "__main__": import sys app = QApplication(sys.argv) MainWindow = TestApp() MainWindow.show() sys.exit(app.exec())
-
Nevermind, I probably don't understand the widget framework well enough (just started using it)
Anyway I got this to work. Seems I need to- add actions and menus
- add menus to menubar
- add menubar to toolbar
- add menubar-actions to toolbar
- add toolbar to main window
from PyQt6.QtWidgets import * from PyQt6.QtGui import * from PyQt6.QtCore import * class Analyzer(QMainWindow): def __init__(self): super().__init__() self.setupUi() def setupUi(self): self.setObjectName("MainWindow") self.resize(400, 400) self.centralwidget = QWidget(self) self.setCentralWidget(self.centralwidget) self.grid_layout = QGridLayout(self.centralwidget) self.label = QLabel("Test", self.centralwidget) self.lineEdit = QLineEdit(self) self.lineEdit.setPlaceholderText("Search...") self.grid_layout.addWidget(self.label, 0, 0, alignment=Qt.AlignmentFlag.AlignCenter) # Create menu bar, toolbar and statusbar objects menubar = self.menuBar() toolbar = QToolBar('Main ToolBar', self) self.statusbar = QStatusBar(self) # add 2 menus to menubar mainMenu = menubar.addMenu("&Swing Studio") helpMenu = menubar.addMenu("&Help") # Create actions self.aboutAction = QAction("About Swing Studio", self) self.settingsAction = QAction("Settings...", self) self.settingsAction.triggered.connect(self.settings) self.helpAction = QAction("Swing Studio Help", self) self.helpAction.triggered.connect(self.about) self.docuAction = QAction("Documentation", self) self.issueAction = QAction("Report Issue", self) self.quitAction = QAction("Quit", self) self.quitAction.triggered.connect(self.byebye) self.searchAction = QWidgetAction(self) self.searchAction.setDefaultWidget(self.lineEdit) # Add actions to menus mainMenu.addAction(self.aboutAction) mainMenu.addSeparator() mainMenu.addAction(self.settingsAction) mainMenu.addSeparator() mainMenu.addAction(self.quitAction) helpMenu.addAction(self.searchAction) helpMenu.addSeparator() helpMenu.addAction(self.helpAction) helpMenu.addSeparator() helpMenu.addAction(self.docuAction) helpMenu.addSeparator() helpMenu.addAction(self.issueAction) # add menus to menubar menubar.addMenu(mainMenu) menubar.addMenu(helpMenu) # add menubar-actions to toolbar toolbar.addActions(menubar.actions()) # add toolbar and statusbar to main window self.addToolBar(toolbar) self.setStatusBar(self.statusbar) # update status bar that we are now ready self.statusbar.showMessage("Ready") def settings(self): QMessageBox.information(self, "Settings", "This is the settings dialog") def about(self): QMessageBox.about(self, "About Swing Studio", "This is my app") def byebye(self): sys.exit() if __name__ == "__main__": import sys app = QApplication(sys.argv) MainWindow = Analyzer() MainWindow.show() sys.exit(app.exec())
-
Hi and welcome to devnet,
macOS does not do menu bar in the window.
Check the bar at the top of the screen where your application name is. You should see what you added there.
You have more information about it in the QMenBar documentation. -
Nevermind, I probably don't understand the widget framework well enough (just started using it)
Anyway I got this to work. Seems I need to- add actions and menus
- add menus to menubar
- add menubar to toolbar
- add menubar-actions to toolbar
- add toolbar to main window
from PyQt6.QtWidgets import * from PyQt6.QtGui import * from PyQt6.QtCore import * class Analyzer(QMainWindow): def __init__(self): super().__init__() self.setupUi() def setupUi(self): self.setObjectName("MainWindow") self.resize(400, 400) self.centralwidget = QWidget(self) self.setCentralWidget(self.centralwidget) self.grid_layout = QGridLayout(self.centralwidget) self.label = QLabel("Test", self.centralwidget) self.lineEdit = QLineEdit(self) self.lineEdit.setPlaceholderText("Search...") self.grid_layout.addWidget(self.label, 0, 0, alignment=Qt.AlignmentFlag.AlignCenter) # Create menu bar, toolbar and statusbar objects menubar = self.menuBar() toolbar = QToolBar('Main ToolBar', self) self.statusbar = QStatusBar(self) # add 2 menus to menubar mainMenu = menubar.addMenu("&Swing Studio") helpMenu = menubar.addMenu("&Help") # Create actions self.aboutAction = QAction("About Swing Studio", self) self.settingsAction = QAction("Settings...", self) self.settingsAction.triggered.connect(self.settings) self.helpAction = QAction("Swing Studio Help", self) self.helpAction.triggered.connect(self.about) self.docuAction = QAction("Documentation", self) self.issueAction = QAction("Report Issue", self) self.quitAction = QAction("Quit", self) self.quitAction.triggered.connect(self.byebye) self.searchAction = QWidgetAction(self) self.searchAction.setDefaultWidget(self.lineEdit) # Add actions to menus mainMenu.addAction(self.aboutAction) mainMenu.addSeparator() mainMenu.addAction(self.settingsAction) mainMenu.addSeparator() mainMenu.addAction(self.quitAction) helpMenu.addAction(self.searchAction) helpMenu.addSeparator() helpMenu.addAction(self.helpAction) helpMenu.addSeparator() helpMenu.addAction(self.docuAction) helpMenu.addSeparator() helpMenu.addAction(self.issueAction) # add menus to menubar menubar.addMenu(mainMenu) menubar.addMenu(helpMenu) # add menubar-actions to toolbar toolbar.addActions(menubar.actions()) # add toolbar and statusbar to main window self.addToolBar(toolbar) self.setStatusBar(self.statusbar) # update status bar that we are now ready self.statusbar.showMessage("Ready") def settings(self): QMessageBox.information(self, "Settings", "This is the settings dialog") def about(self): QMessageBox.about(self, "About Swing Studio", "This is my app") def byebye(self): sys.exit() if __name__ == "__main__": import sys app = QApplication(sys.argv) MainWindow = Analyzer() MainWindow.show() sys.exit(app.exec())
-
-
@Alan-Miller As @SGaist Wrote menus on MacOS are NOT in the application window, but in the top bar of the OS. Adding a menu to application window like you do now violates the OS design guidelines, but it is of course up to you.
-
-
-
@Alan-Miller said in no menu Qt 6.8.1 on mac:
I see my menus in both places
Don't add the menu bar to the toolbar.
-
Yes, I got that resolved. Just one question., Can I change the application name shown in the top bar?
the script is analyzer.py so the app name shown in my screenshot says "python" and my "About" menu says "About analyzer.py". When I click the "About analyzer.py" I do get my messageBox
-