【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
                }
            }
        }
    }
相关推荐
OKkankan7 小时前
多态概念及使用
开发语言·数据结构·c++·算法
jyan_敬言7 小时前
【Docker】Kubernetes部署容器化应用程序
c++·笔记·其他·docker·容器·kubernetes·学习方法
code bean7 小时前
【C++】全局函数和全局变量
开发语言·c++·c#
北冥湖畔的燕雀7 小时前
二叉搜索树:高效查找与删除的实现
数据结构·c++·算法
神仙别闹7 小时前
基于C++实现(控制台)应用二维矩阵完成矩阵运算
开发语言·c++·矩阵
似水এ᭄往昔8 小时前
【C++】--二叉搜索树
开发语言·数据结构·c++
水木姚姚8 小时前
C++程序创建(VS Code)
开发语言·c++
四维碎片8 小时前
【Qt】OpenGL渲染框架
qt·opengl
小龙报8 小时前
【算法通关指南:数据结构与算法篇(五)】树的 “自我介绍”:从递归定义到存储绝技(vector vs 链式前向星)
c语言·数据结构·c++·算法·链表·启发式算法·visual studio
666HZ6668 小时前
C语言——C++的引用
c语言·开发语言·c++