Domanda

C'è un modo per mettere una QMenuBar nella parte inferiore dello schermo (voglio dire, in QMainWindow in basso)?

Sto lavorando al mio progetto di tesi e il mio direttore mi ha chiesto di mettere un QMenuBar nella parte inferiore dello schermo.È possibile? Ho provato a regolare la geometria della barra dei menu.In Qt Designer posso spostare la posizione della barra, ma quando eseguo il mio progetto, la barra dei menu è sempre in alto.

Grazie in anticipo.

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top