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. [MacOS] Global QMenuBar is not clickable
Forum Updated to NodeBB v4.3 + New Features

[MacOS] Global QMenuBar is not clickable

Scheduled Pinned Locked Moved Solved Qt for Python
qt for pythonpython
7 Posts 2 Posters 1.6k 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.
  • W Offline
    W Offline
    wlgns2223
    wrote on last edited by wlgns2223
    #1

    I wanted to make a menubar for a window on MacOs 10.15.6 with PyQt 5.15

    I used QMenuBar class for custom menubar ,created some submenus under 'File' Menu and added it to QMainWindow
    and I can see global menubar is created on the top of display just like the other MacOs.

    I tried both

    QMenuBar()  , QMainWIndow.setMenuBar() and
    QMainWIndow.menubar()
    

    However created global menubar is not clickable. I clicked it but it does not show submenus below 'File' Menu.

    But This way below works fine like Windows Applications but I wanna use native MacOs menubar

    QMainWindow.setMenuBar() and QMainWindow.setNativeMenuBar(False)
    

    Here are codes and images.

    https://imgur.com/a/Yp6c9YW

    import sys
    from PyQt5.QtWidgets import QApplication, QAction, QMenuBar
    from PyQt5.QtGui import QKeySequence
    from PyQt5.QtCore import pyqtSlot, pyqtSignal
    
    
    class MenuBarWidget(QMenuBar):
        sig_new_file = pyqtSignal()
        sig_open_file = pyqtSignal()
        sig_save_file = pyqtSignal()
        sig_page_setup = pyqtSignal()
        sig_print = pyqtSignal()
        sig_exit = pyqtSignal()
        sig_status_bar = pyqtSignal(bool)
    
        def __init__(self):
            super().__init__()
            self.init_menu_file()
    
            # self.init_menu_edit()
            # self.init_menu_format()
            # self.init_menu_view()
            # self.init_menu_help()
            # self.set_all_text()
    
        def init_menu_file(self):
            act_new_file = QAction(self.tr("&File"), self)
            act_new_file.setShortcut(QKeySequence('Ctrl+N'))
            act_new_file.triggered.connect(lambda: self.sig_new_file.emit())
    
            self.act_open_file = QAction('Open', self)
            self.act_open_file.setShortcut(QKeySequence('Ctrl+O'))
            self.act_open_file.triggered.connect(lambda: self.sig_open_file.emit())
    
            self.act_save_file = QAction('Save', self)
            self.act_save_file.setShortcut(QKeySequence('Ctrl+S'))
            self.act_save_file.triggered.connect(lambda: self.sig_save_file.emit())
    
            self.act_print = QAction('Print', self)
            self.act_print.setShortcut(QKeySequence('Ctrl+P'))
            self.act_print.triggered.connect(lambda: self.sig_print.emit())
    
            self.act_quit = QAction('Quit', self)
            self.act_quit.setShortcut(QKeySequence('Ctrl+Q'))
            self.act_quit.triggered.connect(lambda: self.sig_exit.emit())
    
            self.menu_file = self.addMenu(self.tr('&File'))
            self.menu_file.addAction(act_new_file)
            self.menu_file.addAction(self.act_open_file)
            self.menu_file.addAction(self.act_save_file)
            self.menu_file.addSeparator()
            self.menu_file.addAction(self.act_print)
            self.menu_file.addSeparator()
            self.menu_file.addAction(self.act_quit)
    
    
    if __name__ == '__main__':
    
        # Some Test codes.
        import sys
        from PyQt5.QtWidgets import QMainWindow
        from menuBar import MenuBarWidget
    
        class Form(QMainWindow):
    
            def __init__(self):
                super().__init__()
                self.initUI()
    
            def initUI(self):
                self.resize(640, 480)
                self.setWindowTitle('MenuBar')
                self.menu = MenuBarWidget()
                self.setMenuBar(self.menu)
    
        app = QApplication(sys.argv)
        form = Form()
        form.show()
        exit(app.exec_())
    
    1 Reply Last reply
    0
    • SGaistS SGaist

      You can test an older version to see if its related to 5.15.

      However, this rings a bell. Can you test that with PySide2 ?

      Once tested with PySide2, you should check the bug report system to see if this is something known.

      W Offline
      W Offline
      wlgns2223
      wrote on last edited by
      #6

      @SGaist I solved it by myself. It was unfocus and refocus issue in macos

      Same issue here.
      https://forum.qt.io/topic/79478/menubar-does-not-work-until-app-unfocused-and-focused-again-on-macosx/2

      Method Here.
      https://stackoverflow.com/questions/48738805/mac-pyqt5-menubar-not-active-until-unfocusing-refocusing-the-app

      it works perfect.

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

        Hi and welcome to devnet,

        Which version of Qt do you have installed along PyQt5 ?

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

        W 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Which version of Qt do you have installed along PyQt5 ?

          W Offline
          W Offline
          wlgns2223
          wrote on last edited by
          #3

          @SGaist Thank you for your efforts to improve QT community first of all !

          My versions are [MacOs 10.15.6 and PyQt 5.15 ]
          Is this version issue?

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

            You can test an older version to see if its related to 5.15.

            However, this rings a bell. Can you test that with PySide2 ?

            Once tested with PySide2, you should check the bug report system to see if this is something known.

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

            W 2 Replies Last reply
            0
            • SGaistS SGaist

              You can test an older version to see if its related to 5.15.

              However, this rings a bell. Can you test that with PySide2 ?

              Once tested with PySide2, you should check the bug report system to see if this is something known.

              W Offline
              W Offline
              wlgns2223
              wrote on last edited by
              #5

              @SGaist I have tried PyQt5 5.14.2 , 5.13.2 version and Pyside2. None of them works and makes it clickable.
              I guess I coded wrong? or latest macos version problem? MenuBarWidget inherits from QMenuBar(), then returns an custom menu instance to QMainWindow.setMenuBar.setMenuBar(). I can see File menu is created on the native macos menubar BUT IT'S NOT CLICKABLE and DOES NOT SHOW SUBMENUS . lol

              1 Reply Last reply
              0
              • SGaistS SGaist

                You can test an older version to see if its related to 5.15.

                However, this rings a bell. Can you test that with PySide2 ?

                Once tested with PySide2, you should check the bug report system to see if this is something known.

                W Offline
                W Offline
                wlgns2223
                wrote on last edited by
                #6

                @SGaist I solved it by myself. It was unfocus and refocus issue in macos

                Same issue here.
                https://forum.qt.io/topic/79478/menubar-does-not-work-until-app-unfocused-and-focused-again-on-macosx/2

                Method Here.
                https://stackoverflow.com/questions/48738805/mac-pyqt5-menubar-not-active-until-unfocusing-refocusing-the-app

                it works perfect.

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

                  You still shouldn't need a workaround. I'd say it's worth a report since it has been working until now.

                  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
                  1

                  • Login

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