Logo Questions Linux Laravel Mysql Ubuntu Git Menu

How to remove bar from QMainWindow

I'm trying to delete this bar, butI can't get rid of it (it's locate just under the toolbar):

enter image description here

What is the name of that bar,how can I access it? Thank you.

like image 669
xpg94 Avatar asked Jun 25 '14 19:06


3 Answers

What you are calling the toolbar is actually the menu bar and what you are calling the other bar is actually an emtpy toolbar.

The most likely reason you have an empty toolbar is because you created your window using QtDesigner. If you choose a QMainWindow as your starting point, it automatically adds an empty menubar and an empty toolbar to the window. If you don't want the toolbar, find it in the Object Inspector on the right-hand side, right-click and select Remove Toolbar 'mainToolbar' (or whatever other name is the default).

like image 58
RobbieE Avatar answered Nov 13 '22 22:11


If you added that tool bar you probably have a pointer to it? If yes, you can simply call:


in your QMainWindow class. Otherwise you can remove all tool bars from the main window as:

QList<QToolBar *> allToolBars = mainWindow->findChildren<QToolBar *>();
foreach(QToolBar *tb, allToolBars) {
    // This does not delete the tool bar.
like image 31
vahancho Avatar answered Nov 13 '22 21:11


Below adds a little to @RobbieE's answer.

When creating a QMainWindow form, it creates mainToolBar for the user.

If you right click on it and select Remove Toolbar 'mainToolBar' it will be gone.

Or in code in the top of your constructor:


delete ui->mainToolBar; // add this line

Hope that helps.

like image 2
phyatt Avatar answered Nov 13 '22 22:11