1

Is there any way to put a QMenuBar at screen bottom (I mean, at QMainWindow bottom)?

I'm working on my thesis project, and my director asked me to put a QMenuBar at screen bottom. Is this possible?, I have been trying adjusting the menubar geometry. In Qt Designer I can move the bar position, but when I run my project, the menu bar is always up.

Thanks in advance.

Hermandroid
  • 2,120
  • 4
  • 29
  • 35

2 Answers2

3

Don't use the default QMenuBar provided with the QMainWindow. Instead create your own. This proof of concept example creates a new QMenuBar which is added to a QVBoxLayout which was added to the mainwindow:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenuBar* bar = new QMenuBar(this);
    ui->verticalLayout->addWidget(bar);

    QMenu* menu1 = new QMenu("First menu", bar);
    menu1->addMenu("Foo");
    menu1->addMenu("Bar");

    QMenu* menu2 = new QMenu("Second menu", bar);
    menu2->addMenu("Foo");
    menu2->addMenu("Bar");

    bar->addMenu(menu1);
    bar->addMenu(menu2);
}

This works at least in Windows.

  • Thanks for your answer Roku, I'm going to try it later, I really appreciate your help – Hermandroid Feb 22 '12 at 13:35
  • Yes, the QMainWindows doesn't have a vertical layout as default, it must be added manually. –  Feb 22 '12 at 14:58
  • Hi Roku, I'm a bit new in Qt, does that mean that I must place a QVerticalLayout in my QMainWindow, I have triyed that and I was wondering how to maintain the vertical layout in the screen bottom when the window is resized, but the layout is always in the same place, is there a way to adujst the layout when the window is resized?. Thanks in advance. – Hermandroid Feb 22 '12 at 15:04
  • 1
    If you start from empty QMainWindow, do this: First add the widgets you need to main window, for example QTextEdits and QListWidgets. Then select the main window. Then select "Lay out vertically" from the top tool bar. Now all widgets on the main window are vertically layouted. When the new QMenuBar is added in the constructor, it is added to the bottom of the layout. Don't drag and drop the layouts from the left pane (widget box), they are quite difficult to use this way. I really recommend using an hour for just playing with different layouts, spacers and widgets and learning how they work. –  Feb 22 '12 at 15:37
  • Thank you very much Roku, I really appreciate your help, I'm going to check the layouts on that way. – Hermandroid Feb 22 '12 at 15:55
0

I've placed menus in the QDockWidget so I assume it is also possible to place menu bar at the bottom.

But you must do it programmaticaly. QMenuBar inherits QWidget, so just add a QWidget at the bottom of QMainWindow, then create a QMenuBar specifying this QWidget as a parent widget.

Dmitriy
  • 5,357
  • 8
  • 45
  • 57