Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide6 QMenuBar Issue on MacOS
Qt 6.11 is out! See what's new in the release blog

PySide6 QMenuBar Issue on MacOS

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 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.
  • J Offline
    J Offline
    JimRyan
    wrote on last edited by JimRyan
    #1

    I developed a PySide6 app in VS Code on Windows and let GitHub Actions make MacOS executables. Everything works very well, except that the QMenuBar doesn't work on MacOS. It doesn't show all the actions/submenus. I don't know much about development for MacOS. Any advice most appreciated!

    Code snippet:

    class CustomMenuBar(QMenuBar):
        def __init__(self, view, app, experiment_controller):
            super().__init__()
            self.view = view
            self.app = app
            self.experiment_controller = experiment_controller
            file_menu = self.addMenu("Application")
            quit_action = file_menu.addAction("Quit")
            quit_action.triggered.connect(self.quit_app)
            
            experiment_menu = self.addMenu("Experiment")
            open_experiment_action = experiment_menu.addAction("Open Experiment File")
            open_experiment_action.triggered.connect(self.load_experiment_file)
            exp_submenu = QMenu("Configure Experiment", self)
            experiment_menu.addMenu(exp_submenu)
            create_new_exp_action = QAction("Create new experiment", self)
            exp_submenu.addAction(create_new_exp_action)
            create_new_exp_action.triggered.connect(self.show_blank_experiment_configuration_form)
            experiment_menu.addMenu(exp_submenu)
            edit_current_exp_action = QAction("Edit current experiment", self)
            exp_submenu.addAction(edit_current_exp_action)
            edit_current_exp_action.triggered.connect(self.show_loaded_experiment_configuration_form)
            close_experiment_action = experiment_menu.addAction("Close Experiment")
            close_experiment_action.triggered.connect(self.close_experiment)
            save_experiment_action = experiment_menu.addAction("Save Current")
            save_experiment_action.triggered.connect(self.save_experiment)
    
            help_menu = self.addMenu("Help")
            welcome_action = help_menu.addAction("Welcome")
            welcome_action.triggered.connect(self.show_welcome)
            manual_action = help_menu.addAction("User's Manual")
            manual_action.triggered.connect(self.show_manual)
    
            new_submenu = QMenu("Theme", self)
            help_menu.addMenu(new_submenu)
            dark_theme_action = QAction("Dark", self)
            new_submenu.addAction(dark_theme_action)
            dark_theme_action.triggered.connect(self.set_dark_theme)
    
            light_theme_action = QAction("Light", self)
            new_submenu.addAction(light_theme_action)
            light_theme_action.triggered.connect(self.set_light_theme)
    

    Pictures of how the code works well on Windows:
    menubar1.png
    menubar2.png

    On MacOS, the QMenuBar items get pushed up into the MacOS menu bar itself. But the Experiment->Configure Experiment submenu does not appear, and the Application menu does not appear. The help->Theme->Dark/Light do appear, so the issue isn't specific to side-submenus.

    I tried

    setNativeMenuBar(False)
    

    but it only made the entire menu bar vanish.

    If this menu bar is just not workable on MacOS, I will have to remove the menu bar and use buttons/popups.

    Many thanks for any tips.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JimRyan
      wrote on last edited by
      #2

      SOLVED. There may be other solutions, but my solution was a semantic one. I got rid of strings that sound like menu items: configure, close, and edit. I also removed the Application menu, since Quit was likely to trigger the OS to put the menu in the MacOS menu bar.

      Perhaps only removing the application menu was necessary. Anyway, it's fixed.

      1 Reply Last reply
      0
      • J JimRyan has marked this topic as solved on
      • J Offline
        J Offline
        JimRyan
        wrote on last edited by
        #3

        So, MacOS decides whether an apps menu bar goes into the MacOS menu bar based on the semantics of strings? Wow. (There is an out: setNativeMenuBar(False), but it didn't work for me.)

        I'd love to hear from any experts about this.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          macOS has certain rules (as other OS do as well) to have a consistent user experience and Qt helps to put things into the right place automatically.
          For example, the settings are under Preferences in the application's name menu. User don't have to hunt down for these kind of things.

          On macOS the default QMainWindow menu bar is indeed at the top of the screen which is normal and expected.

          Taking a look at your code and the picture you posted, I would suggest to redesign things a bit. For example, having the dark/light theme switch under Help is rather unexpected.

          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

          • Login

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