Rodrigo E. Principe Rodrigo E. Principe - 1 year ago 120
Python Question

Show menu bar (always) using python Qt4 (pyqt) in ubuntu 14.04

I am starting with pyQt4, aiming to make a simple application. My OS is Ubuntu 14.04 and I am using pyQt4 Designer, but also trying to make it from scratch. When I create a menu bar it doesn't appear unless I maximize the window. I have realized, looking to some other soft made with pyQt like QGIS, that this issue may be normal in Ubuntu.

The question:
is there any way to force the application to show the menu bar even if it is not maximized?

I could put the code, but I think is irrelevant.
Thank you.

Answer Source

It's not a problem of Qt, it's a feature of Ubuntu's Unity shell called global menu bar. And since Ubuntu 14.04 it can be switched off.

But if you want your menu to take its place on top of a window regardless of graphical shell preferences, you should use Qt menu bar instead of native one:

class Window(QtGui.QMainWindow):
    def __init__(self):

        toolMenu = QtGui.QMenuBar()
        toolMenu.setNativeMenuBar(False) # <--

        for i in range(5):
            _ = toolMenu.addAction('Action {}'.format(i))

If you prefer, you can make this change in Qt Designer instead. Select your QMenuBar object in the Object Inspector tree, scroll down in the Property Editor to the QMenuBar section, and uncheck the nativeMenuBar checkbox.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download