当软件有很多工具条时,会有remove工具条的需求,后面需要时,再add进来。
那么,先执行removeToolBar(),再执行addToolBar(),工具条是不会显示出来的;
原因其实很简单,官方文档写的很清楚,remove时并并不是真的删除,只是隐藏了而已,再次add后,ToolBar依旧是隐藏状态,所以不显示
void QMainWindow::removeToolBar(QToolBar *toolbar)
Removes the toolbar from the main window layout and hides it. Note that the toolbar is not deleted.
同理,Qt 状态栏 添加/移除 QWidget 也是同样的道理,移除后只是隐藏,添加并不改变QWidget 的状态,需要手动调用show().
void QStatusBar::removeWidget(QWidget *widget)
Removes the specified widget from the status bar.
Note: This function does not delete the widget but hides it. To add the widget again, you must call both the addWidget() and show() functions.