【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
                }
            }
        }
    }
相关推荐
m0_51801948几秒前
C++代码混淆与保护
开发语言·c++·算法
m0_569881473 分钟前
C++中的智能指针详解
开发语言·c++·算法
2401_8735449217 分钟前
基于C++的游戏引擎开发
开发语言·c++·算法
add45a17 分钟前
C++中的组合模式
开发语言·c++·算法
無限進步D19 分钟前
简单贪心算法 cpp
c++·算法·贪心算法·蓝桥杯·入门·竞赛
2501_9454235421 分钟前
模板编程中的SFINAE技巧
开发语言·c++·算法
承渊政道23 分钟前
【优选算法】(实战感悟二分查找算法的思想原理)
c++·笔记·学习·算法·leetcode·visual studio code
☆56623 分钟前
C++中的策略模式应用
开发语言·c++·算法
2401_8845632425 分钟前
C++中的原型模式变体
开发语言·c++·算法
干啥啥不行,秃头第一名38 分钟前
C++与机器学习框架
开发语言·c++·算法