【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
                }
            }
        }
    }
相关推荐
KyollBM25 分钟前
【CF】Day75——CF (Div. 2) B (数学 + 贪心) + CF 882 (Div. 2) C (01Trie | 区间最大异或和)
c语言·c++·算法
feiyangqingyun37 分钟前
Qt/C++开发监控GB28181系统/取流协议/同时支持udp/tcp被动/tcp主动
c++·qt·udp·gb28181
CV点灯大师39 分钟前
C++算法训练营 Day10 栈与队列(1)
c++·redis·算法
jllws11 小时前
Qt学习及使用_第1部分_认识Qt---学习目的及技术准备
qt·c++框架
成工小白2 小时前
【C++ 】智能指针:内存管理的 “自动导航仪”
开发语言·c++·智能指针
sc写算法2 小时前
基于nlohmann/json 实现 从C++对象转换成JSON数据格式
开发语言·c++·json
SunkingYang2 小时前
C++中如何遍历map?
c++·stl·map·遍历·方法
Andrew_Xzw2 小时前
数据结构与算法(快速基础C++版)
开发语言·数据结构·c++·python·深度学习·算法
库库的里昂2 小时前
【C++从练气到飞升】03---构造函数和析构函数
开发语言·c++
到点就困告2 小时前
海康工业相机SDK二次开发(VS+QT+海康SDK+C++)
数码相机·qt·海康