【Qt QML】TabBar的用法

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

cpp 复制代码
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
                }
            }
        }
    }
相关推荐
QiLinkOS2 小时前
第三视觉理解徐玉生与他的商业活动(30)
大数据·c++·人工智能·算法·开源协议
mit6.8242 小时前
阅读的核心,是再读
c++
upgrador4 小时前
基础知识:C++ STL构造函数的左闭右开惯例及其实现原理
开发语言·c++
尘中远5 小时前
【Qwt 7.0 系列】坐标轴与刻度系统 —— 刻度引擎、网格、图例与刻度朝内
qt·数据可视化·qcustomplot·qwt·工业软件·科学绘图
凯瑟琳.奥古斯特6 小时前
K次取反最大化数组和解法(力扣1005)
开发语言·c++·算法·leetcode·职场和发展
林中青木6 小时前
CT重构原理及C++代码实现
c++·计算机视觉·重构
满天星83035776 小时前
Protobuf的介绍及使用
c++
☆cwlulu6 小时前
调试排查工具介绍(gdb、strace、Valgrind等)
开发语言·c++·嵌入式硬件·ubuntu
卷无止境7 小时前
C++ 存储类说明符(Storage Class Specifier)大横评
c++·后端
卷无止境7 小时前
C++ 编程的一大坑:非常量全局变量是"万恶之源"
c++·后端