PYPL PYPL - 1 month ago 9
Python Question

Create a QMenubar under QTabWidget tabs

I'm trying to find a way to insert

QMenuBar
under
QTabWidget
. Could not find any solution, tried to get
QMenuBar
intilization from generated
.ui
file of
QMainWindow
but no luck

self.menubar = QtGui.QMenuBar(self.myTab)
self.menubar.setGeometry(QtCore.QRect(0, 0, 700, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuOptions = QtGui.QMenu(self.menubar)
self.menuOptions.setObjectName(_fromUtf8("menuOptions"))
self.myTab.setMenuBar(self.menubar)


I need it to be like this because my app will have custom option sections for each tab view

QMenuBar under QTabWidget tab

Answer

Guys on the official QT Forum helped me...

The solution is that you can add QMenuBar to TAB's layout (You cannot do this from QT Designer)

    self.menuBar = QtGui.QMenuBar()
    self.menuOptions = QtGui.QMenu("Options", self.menuBar)
    self.actionQuit = QtGui.QAction('Quit', self)
    self.actionQuit.triggered.connect(self.close)

    self.menuOptions.addAction(self.actionQuit)
    self.menuBar.addAction(self.menuOptions.menuAction())

    #WARN! TAB widget must have a layout!
    self.ui.UDETabs.widget(0).layout().setMenuBar(self.menuBar)