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:
To look like this example:
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:
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)
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.