qtqmainwindowqtoolbarqmenubar

How to reduce the width of QMenuBar and QToolBar in a QMainWindow


A menu bar and a toolbar occupying less than a third of the window width

In my MainWindow, menuBar and toolBar contents are a few that will occupy only a small portion of on the left side of the main window, and the rest of the portion is left empty.

I have an information frame with some widgets in it on the right side of the centerwidget.

Can I push the information frame into the empty menu bar space? As menubar and toolbar occupy only the left portion of the mainwindow, can I use the entire right portion for the information frame?


Solution

  • You can't use that space through layout because this space is already taken by the main menu and the toolbar. There is no option to put something in this space.

    But you can add a main window's child without putting it in any layout. It will be shown above all layed out children. But you will have to calculate and adjust size and position of this widget manually.

    For example, add the following code to the main window's constructor:

    QPushButton* b = new QPushButton("TEST", this);
    b->move(200, 0);
    

    It looks like this:

    screenshot