How to remove bar from QMainWindow

自作多情 提交于 2019-12-10 14:52:57

问题


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

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


回答1:


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);
}



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/24416781/how-to-remove-bar-from-qmainwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!