1

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

neowinston
  • 7,584
  • 10
  • 52
  • 83

1 Answers1

2

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.

Community
  • 1
  • 1
Viktor Kerkez
  • 45,070
  • 12
  • 104
  • 85
  • Thanks for your answer, Viktor. I tried you code as is, on a simple project, but the menu didn't show up. What could I be missing? – neowinston Sep 19 '13 at 13:47
  • @Winston http://i.imgur.com/G1ndBWF.png this is what I get. I clicked the `About python` a few times and you can see that the `shown` is displayed in the console window. – Viktor Kerkez Sep 19 '13 at 14:14
  • Yes, that's what I need. I'm using Eclipse (and I tried also using Terminal) and PyQt4, but I can't get the same result as you did. This is the result: http://tinyurl.com/aboutboxpyqt – neowinston Sep 19 '13 at 14:51
  • @Winston Wow, weird... I just tested it and it works with PySide but it does not work with PyQt4. – Viktor Kerkez Sep 19 '13 at 14:53
  • Great! Thanks a lot! I'm checking it all! – neowinston Sep 19 '13 at 15:22