xpg94
xpg94

Reputation: 513

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.

Upvotes: 5

Views: 9452

Answers (3)

phyatt
phyatt

Reputation: 19122

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:

ui->setupUi(this);

delete ui->mainToolBar; // add this line

Hope that helps.

Upvotes: 2

RobbieE
RobbieE

Reputation: 4360

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).

Upvotes: 8

vahancho
vahancho

Reputation: 21250

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

removeToolBar(toolbar);

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.
    mainWindow->removeToolBar(tb);
}

Upvotes: 4

Related Questions