【Qt QML】TabBar的用法

Qt Quick中的TabBar提供了一个基于选项卡的导航模型。TabBar由TabButton控件填充,并且可以与任何提供currentIndex属性的布局或容器控件一起使用,例如StackLayout或SwipeView。
请添加图片描述

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Window {
    id: win
    width: 640
    height: 480
    visible: true
    title: qsTr("Tab Page")

    ListModel {
        id: pageModel
        ListElement{
            pageName : "Home"
            pageColor : "steelblue"
        }
        ListElement{
            pageName : "FirstPage"
            pageColor : "tomato"
        }
        ListElement{
            pageName : "SecondPage"
            pageColor : "slateblue"
        }
    }

    TabBar {
        id: tabBar
        width: parent.width
        height: 50
        Repeater {
            model: pageModel
            TabButton {
                text:  pageName
                height: parent.height
                background: Rectangle {
                    implicitHeight: parent.height
                    color: pageColor
                }
            }
        }
    }

    StackLayout {
        anchors.top: tabBar.bottom
        height: parent.height
        width: parent.width
        currentIndex: tabBar.currentIndex
        Repeater {
            model: pageModel
            Rectangle {
                id: homeTab
                width: parent.width
                height: parent.height
                color: pageColor
                Text {
                    id: pageText
                    text: pageName
                    anchors.centerIn: parent
                }
            }
        }
    }

相关推荐

  1. nc

    2024-04-26 06:26:04       63 阅读
  2. QueryWrapper

    2024-04-26 06:26:04       30 阅读
  3. axios

    2024-04-26 06:26:04       33 阅读
  4. React <> </>

    2024-04-26 06:26:04       32 阅读
  5. pymysql基本

    2024-04-26 06:26:04       60 阅读
  6. css_auto

    2024-04-26 06:26:04       56 阅读
  7. 关于QUOTENAME

    2024-04-26 06:26:04       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-26 06:26:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-26 06:26:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-26 06:26:04       82 阅读
  4. Python语言-面向对象

    2024-04-26 06:26:04       91 阅读

热门阅读

  1. CocoaPods使用详解

    2024-04-26 06:26:04       26 阅读
  2. 39 vue.js

    2024-04-26 06:26:04       33 阅读
  3. MATLAB初学者入门(16)—— 图搜索算法

    2024-04-26 06:26:04       36 阅读
  4. 4、Flink执行模式(流/批)详解(下)

    2024-04-26 06:26:04       32 阅读
  5. golang 锁bug 记录

    2024-04-26 06:26:04       33 阅读
  6. HCIP-Datacom-ARST必选题库_ICMP【3道题】

    2024-04-26 06:26:04       33 阅读
  7. Dockerfil 构建上下文 build -f 选项 加快构建速度

    2024-04-26 06:26:04       42 阅读
  8. 关于kafka,关于消息队列、消息协议

    2024-04-26 06:26:04       32 阅读
  9. lua中的pcall和xpcall和直接调用一个函数的区别

    2024-04-26 06:26:04       30 阅读