我想构建一个具有两个选项卡的单窗口应用程序。如何在窗口上设置两个选项卡并单击切换,就像浏览器的窗口和选项卡一样?
PS:这两个选项卡的按钮和文本小部件布局不同,功能也不同。
最佳答案
http://doc.qt.io/qt-5/qtabwidget.html#details
The
QTabWidget
class provides a stack of tabbed widgets.A tab widget provides a tab bar (see
QTabBar
) and a "page area" that is used to display pages related to each tab. By default, the tab bar is shown above the page area, but different configurations are available (seeTabPosition
). Each tab is associated with a different widget (called a page). Only the current page is shown in the page area; all the other pages are hidden. The user can show a different page by clicking on its tab or by pressing its Alt+letter shortcut if it has one.The normal way to use
QTabWidget
is to do the following:
- 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()
orinsertTab()
to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.The position of the tabs is defined by
tabPosition
, their shape bytabShape
....
这就是你的答案。
编辑:链接到一个例子,也是。
http://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html
更新:除了使用
QTabWidget
带来的所有优势之外,标签的一些附加功能随 QDockWidget
一起提供。 ,就像把它们撕成一个单独的窗口。我用过 QDockWidgets
最近获得几乎相同的选项卡外观,但在撕下烘烤,右键单击以查看选项卡列表。希望有帮助。
关于Qt - 如何构建多标签窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16704896/