Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. no menu Qt 6.8.1 on mac
Forum Updated to NodeBB v4.3 + New Features

no menu Qt 6.8.1 on mac

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 319 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Miller
    wrote on last edited by
    #1

    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.

    Screen Shot 2025-01-12 at 12.41.56 PM.png

    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())
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alan Miller
      wrote on last edited by
      #3

      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
        Screen Shot 2025-01-12 at 15.27.35 PM.png Screen Shot 2025-01-12 at 15.27.25 PM.png
      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())
      
      jsulmJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alan Miller
          wrote on last edited by
          #3

          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
            Screen Shot 2025-01-12 at 15.27.35 PM.png Screen Shot 2025-01-12 at 15.27.25 PM.png
          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())
          
          jsulmJ 1 Reply Last reply
          0
          • A Alan Miller has marked this topic as solved on
          • A Alan Miller

            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
              Screen Shot 2025-01-12 at 15.27.35 PM.png Screen Shot 2025-01-12 at 15.27.25 PM.png
            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())
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Alan Miller has marked this topic as solved on
            • A Offline
              A Offline
              Alan Miller
              wrote on last edited by
              #5

              Thanks As @SGaist and @jsulm

              .... in the top bar of the OS. ....

              Ah, now I get it; I didnt realize what you meant by top bar previously. I thought you meant a "bar" within the Qt.
              I see my menus in both places. I'll have to run my code on Win, Linux and I'll clean that up.

              eg.png

              jsulmJ 1 Reply Last reply
              0
              • A Alan Miller

                Thanks As @SGaist and @jsulm

                .... in the top bar of the OS. ....

                Ah, now I get it; I didnt realize what you meant by top bar previously. I thought you meant a "bar" within the Qt.
                I see my menus in both places. I'll have to run my code on Win, Linux and I'll clean that up.

                eg.png

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @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.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alan Miller
                  wrote on last edited by
                  #7

                  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

                  jsulmJ 1 Reply Last reply
                  0
                  • A Alan Miller

                    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

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @Alan-Miller https://doc.qt.io/qt-6/qcoreapplication.html#applicationName-prop

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved