2

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

PYPL
  • 1,819
  • 1
  • 22
  • 45

2 Answers2

1

QMenuBar is just a widget. You can put it everywhere.

Why you get your menubar from .ui, instead of creating your own?

Also remember, that it will work only on Windows. On MacOs and Linux with DE that support global menu it will not work as you want.

RazrFalcon
  • 787
  • 7
  • 17
0

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)
PYPL
  • 1,819
  • 1
  • 22
  • 45