• QML控件类型:TabBar


    一、描述

    TabBar 继承自 Container。提供了一个基于标签的导航模型。允许用户在不同的视图或子任务之间切换。

    TabBar 填充了 TabButton 控件,可以与任何提供 currentIndex 属性的布局或容器控件一起使用,例如 StackLayout 或 SwipeView

    1. import QtQuick
    2. import QtQuick.Controls
    3. import QtQuick.Layouts
    4. Window {
    5. width: 640
    6. height: 480
    7. visible: true
    8. title: qsTr("Hello World")
    9. TabBar {
    10. id: bar
    11. width: parent.width
    12. TabButton {
    13. text: qsTr("Home")
    14. }
    15. TabButton {
    16. text: qsTr("Discover")
    17. }
    18. TabButton {
    19. text: qsTr("Activity")
    20. }
    21. }
    22. StackLayout {
    23. width: parent.width
    24. currentIndex: bar.currentIndex
    25. Item {
    26. id: homeTab
    27. }
    28. Item {
    29. id: discoverTab
    30. }
    31. Item {
    32. id: activityTab
    33. }
    34. }
    35. }

    TabBar 通常填充有一组静态选项卡按钮,这些按钮被内联定义为 TabBar 的子项。

    1.1、调整标签大小

    默认情况下,TabBar 会调整其按钮的大小以适应控件的宽度,可用空间平均分配给每个按钮。可以通过为按钮设置显式宽度来覆盖默认的调整大小行为。

    以下示例说明了如何将每个选项卡按钮保持在其隐式大小,而不是调整大小以适应选项卡栏:

    1. import QtQuick
    2. import QtQuick.Controls
    3. import QtQuick.Layouts
    4. Window {
    5. width: 640
    6. height: 480
    7. visible: true
    8. title: qsTr("Hello World")
    9. TabBar {
    10. id: bar
    11. width: parent.width
    12. TabButton {
    13. text: "First"
    14. width: implicitWidth
    15. }
    16. TabButton {
    17. text: "Second"
    18. width: implicitWidth
    19. }
    20. TabButton {
    21. text: "Third"
    22. width: implicitWidth
    23. }
    24. }
    25. StackLayout {
    26. width: parent.width
    27. currentIndex: bar.currentIndex
    28. Item {
    29. id: homeTab
    30. }
    31. Item {
    32. id: discoverTab
    33. }
    34. Item {
    35. id: activityTab
    36. }
    37. }
    38. }

     

    1.2、轻弹标签

    如果按钮的总宽度超过标签栏的可用宽度,它会自动变为可轻弹的。

    1. import QtQuick
    2. import QtQuick.Controls
    3. import QtQuick.Layouts
    4. Window {
    5. width: 640
    6. height: 480
    7. visible: true
    8. title: qsTr("Hello World")
    9. TabBar {
    10. id: bar
    11. width: parent.width
    12. Repeater {
    13. model: ["First", "Second", "Third", "Fourth", "Fifth"]
    14. TabButton {
    15. text: modelData
    16. width: Math.max(100, bar.width / 5)
    17. }
    18. }
    19. }
    20. StackLayout {
    21. width: parent.width
    22. currentIndex: bar.currentIndex
    23. Item {
    24. id: homeTab
    25. }
    26. Item {
    27. id: discoverTab
    28. }
    29. Item {
    30. id: activityTab
    31. }
    32. }
    33. }

     

    二、属性成员

    1、contentHeight : real / contentWidth : real

    内容高度 / 宽度。用于计算 TabBar 的总隐式高度 / 宽度。

    2、position : enumeration

    TabBar 的位置。默认值是特定于样式的。

    • TabBar.Header:顶部,作为窗口或页面标题。
    • TabBar.Footer:底部,作为窗口或页面页脚。

    如果 TabBar 被指定为 ApplicationWindow Page 的页眉或页脚,则会自动设置适当的位置。

    三、附加属性成员

    1、【只读】TabBar.index : int

     TabBar 中每个 TabButton 的索引。它附加到 TabBar 的每个 TabButton

    2、【只读】TabBar.position : enumeration

    TabBar 的位置。它附加到 TabBar 的每个 TabButton

    3、【只读】TabBar.tabBar : TabBar

    管理此 TabButton 的 TabBar 。它附加到 TabBar 的每个 TabButton

  • 相关阅读:
    测试用例、测试套件、测试加载器的用法
    TS中的泛型精简(快速掌握)
    【python笔记】第十三节 常用模块
    通达信交易接口分时做T的指标公式分享
    有哪些免费的PPT模板网站,推荐这6个PPT模板免费下载网站!
    Mybatis插件机制
    Django 密码管理:安全实践与技术深入
    SpringBoot 的版本、打包、Maven
    基于OpenStreetMap+PostGIS的地理位置系统 论文文档+参考论文文献+项目源码及数据库文件
    亚马逊云科技基于 Polygon 推出首款 Amazon Managed Blockchain Access,助 Web3 开发人员降低区块链节点运行成本
  • 原文地址:https://blog.csdn.net/kenfan1647/article/details/125481701