문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top