Question

I am using python with Pyqt4 for building app on Ubuntu and seems I have trouble with menubar that doesn't show up, thanks for any help. here is the code:

import sys
from PyQt4 import QtGui
class Example(QtGui.QMainWindow):              
    def __init__(self):
         super(Example, self).__init__()        
         self.initUI()        
    def initUI(self):                      
         exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)        
         exitAction.setShortcut('Ctrl+Q')
         exitAction.setStatusTip('Exit application')
         exitAction.triggered.connect(QtGui.qApp.quit)
         self.statusBar()
         menubar = self.menuBar()
         fileMenu = menubar.addMenu('&File')
         fileMenu.addAction(exitAction)        
         self.setGeometry(300, 300, 300, 200)
         self.setWindowTitle('Menubar')    
         self.show()       
def main():    
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
if __name__ == '__main__':
     main()  

Excuse me if the indentation wouldn't be correct but I think it is.

Was it helpful?

Solution

In ubuntu menubar is outside the application . You can find it in global menu

OTHER TIPS

Try This:

menuBar = self.menuBar()
menuBar.setNativeMenuBar(False)

There is nothing wrong in your code. First you should run your code and maximize your GUI(Graphical User Interface) and you can see that your code run fine and you can understand what actually happen in Ubuntu. Actually Ubuntu always show the menu bar (also your GUI) at the top of the screen no matter what the size of your application.

Actually there is your menu. You can just full screen your application and it would be on the top of the window if you hover your mouse on that.

This is Ubuntu mode of visualisation, exactly like your browser that if you hover your mouse over the menu bar, you can see it!

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