0

I'm building a PyQt5 app and would like to display some basic "about" information. I figured the QtWidgets.QMessagebox.about would be a good implementation:

class gGuiGlueApplication(GlueApplication):

   def __init__(self):
      ...
      menu_about_ggui = self.menuBar().addMenu("&gGui Help") 
      menu_about_ggui.addAction("About gGui", self.show_about_ggui)
      ...    

   def show_about_ggui(self):
        """Displays about gGui Message Box"""
        QtWidgets.QMessageBox.about(
            self,
            "About gGui",
            "gPhoton Graphical User Interface (gGui)\n"
            "Developed by Duy Nguyen, Scott Fleming\nVersion: "
            + __version__
            + "\n\ngGui is provided under the AURA Software License. "
            "Please see the included license for details.",
        )

I've tested personally on Windows and Red Hat Enterprise Linux 7; everything looks correct. The about button is under the right menu as "About gGui" and displays the appropriate information:

Windows Menu

Windows About

My collaborator noticed on macOS though, it doesn't appear this way. The about option isn't visible in the menu I made, rather it's under the "Python" menu, labeled incorrectly as "About Python":

macOS Empty Menu

macOS About Python

Understandably this is naturally where about information goes on macOS, but it isn't obvious to our users that "python" is our application. It appears macOS is overriding our placement and naming of the about option. We would like to, at least, have it say "About gGui" rather than the generic "About Python". As per the Qt QMenu.addAction Docs, the first argument dictates the option title, and as per the Qt QMessageBox.about Documentation, the first argument dictates the "title".

How can we force change the about text in macOS to appear as "About gGui", and is it even possible to force the about information to the appropriate menu to be consistent across platforms?

Thanks in advance!

Other information: Python 3.7.1, PyQt5 5.13.2, PyQt5 SIP 12.7.0, QtPy 1.9.0

P.S. Please ignore the "Load gGui Sample Data" option on the Windows Menu screenshot

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
dtn5ah
  • 11
  • 2

1 Answers1

0

The simplest way to solve this would seem to be by using the following option:

QApplication.setAttribute(Qt.AA_DontUseNativeMenuBar)

This will give your application menu-bars like you would see in Windows / Linux, rather than the system menu-bar at the top of the screen. Individual menu-bars can also be controlled via the setNativeMenuBar method. However, this approach may not be acceptable to some users on macOs.

According to Qt for macOs: Menu Bar, an alternative solution would be to use the menu-role of the action to control how the about menu-item is displayed:

action = QAction(self)
action.triggered.connect(self.show_about_ggui)
action.setMenuRole(QAction.AboutRole)
menu_about_ggui.addAction(action)

For this to work correctly though, you would also need to set your application name properly, so that it replaces the default "Python". For solutions to that problem, see this question:

ekhumoro
  • 115,249
  • 20
  • 229
  • 336