1

I have a simple GUI with QWidget as my main class and I need to create a submenu like this:

the main class 'QMainWindow'

when i try using QMenuBar the result is like this:

main class 'QWidget'

How can i create submenu like the first picture? Should I change my main class to QMainWindow if I want the result like the first picture?

code:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Widget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.setWindowTitle("Network Automation")
        #self.setFixedSize(350, 500)

        #Menubar
        filemenu = QMenuBar()
        menu = filemenu.addMenu('&File')
        submenu = menu.addMenu('&Open File')

        layout = QGridLayout(self)
        layout.addWidget(filemenu, 0, 1)


app = QApplication(sys.argv)
app.setStyle('Plastique')
app.processEvents()
window = Widget()
window.show()
sys.exit(app.exec_())

Please help.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
zNed
  • 11
  • 5

1 Answers1

1

Presumably you want to change the

submenu = menu.addMenu('&Open File')

to

openaction = menu.addAction('&Open File')

Aleš Erjavec
  • 1,086
  • 7
  • 11
  • and how can i get the same result like first picture, on the second picture i got much margin not like first picture? – zNed Jul 24 '17 at 09:00