Qt - 如何构建多标签窗口?

标签 qt

我想构建一个具有两个选项卡的单窗口应用程序。如何在窗口上设置两个选项卡并单击切换,就像浏览器的窗口和选项卡一样?

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 (see TabPosition). 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:

  1. Create a QTabWidget.
  2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
  3. Insert child widgets into the page widget, using layouts to position them as normal.
  4. Call addTab() or insertTab() 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 by tabShape.

...



这就是你的答案。

编辑:链接到一个例子,也是。

http://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html

更新:除了使用 QTabWidget 带来的所有优势之外,标签的一些附加功能随 QDockWidget 一起提供。 ,就像把它们撕成一个单独的窗口。我用过 QDockWidgets最近获得几乎相同的选项卡外观,但在撕下烘烤,右键单击以查看选项卡列表。

希望有帮助。

关于Qt - 如何构建多标签窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16704896/

相关文章:

macos - Qt Creator 在链接/usr/local/lib 时运行程序失败

c++ - 强制 Qt5 从 exe 目录加载 SSL dll

python - Pyqt:获取光标下的文本

c++ - C++中的netcat命令

python - PySide QThread.terminate() 导致致命的 python 错误

c++ - 异步 Qt 模型加载到 QML GridView

c++ - 如何在 C++/Qt 中递归地将数据写入文本文件

qt - 在 Ubuntu 16.04 上配置 Qt 5.9.5

c++ - Qt 中的自定义和默认消息处理程序

c++ - 从 N9 上的 Apps Screen 恢复 MeeGo Harmattan Qt 应用程序