Question

I'm using PyQt and for packing my application to Mac I'm using py2app.

How do I add an "About Box" to the main menu:

enter image description here

To look like this example:

enter image description here

Was it helpful?

Solution

To add an about menu there, you just have to add it to the Help submenu of your menuBar().

import sys
from PySide import QtGui, QtCore

class Window(QtGui.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        help_menu = QtGui.QMenu('&Help')
        about = help_menu.addAction('&About')
        about.triggered.connect(self.show_about)
        self.menuBar().addMenu(help_menu)

    def show_about(self):
        print 'shown'

app = QtGui.QApplication(sys.argv)
win = Window()
win.show()
app.exec_()

The problem is that the title of the application will be python and the About will be About python. To change that, since you already use py2app, you should take look at this question

For PyQt4 it's a little bit different. See the documentation.

Two relevant things:

  1. Do not call QMainWindow.menuBar() to create the shared menu bar, because that menu bar will have the QMainWindow as its parent. You must create a menu bar that does not have a parent.

    menuBar = QtGui.QMenuBar(None)

  2. The application name is fetched from the Info.plist file (see note below). If this entry is not found no About item will appear in the Application Menu.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top