上一篇文章介绍如何对QMessgeBox进行使用。本文紧接上文内容继续对Qt的窗体文件开发介绍。
一般主界面会有很多控件和交互区域;如果把所有的控件都放在一个界面全部显示,整个界面就会显得非常臃肿繁琐。那么使用分页式的表格窗体布局就能将不同类型的控件布局到不同的窗体之中,再根据需要选择即可。Qt提供多种叠加窗体布局,如QStackedWidget、QToolBox和QTabWidget等。本文主要介绍QTabWidget的使用,其他窗体使用方式类似。
翻页式表格窗体 QTabWidget
QTabWidget提供像书签式的一页一页的窗口,需要显示哪一页,点击对应的书签标题切换过去即可。
QTabWidget的帮助中对其一般使用流程描述如下:
• Create a QTabWidget.
• Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
• Insert child widgets into the page widget, using layouts to position them as normal.
• Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.
打开上文的项目,我们在ui文件中新建一个tabWigget,将前期的一些空间拖入第一个Page 1之中。
Ui编辑器右侧属性窗口可以对每一页的标题、对象名和图标等进行修改: