【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
                }
            }
        }
    }
相关推荐
你真是饿了43 分钟前
1.C++入门基础
开发语言·c++
elseif1231 小时前
【C++】并查集&家谱树
开发语言·数据结构·c++·算法·图论
凯子坚持 c1 小时前
C++基于微服务脚手架的视频点播系统---客户端(4)
数据库·c++·微服务
问好眼1 小时前
【信息学奥赛一本通】1275:【例9.19】乘积最大
c++·算法·动态规划·信息学奥赛
coder攻城狮1 小时前
VTK系列1:在屏幕绘制多边形
c++·3d
HAPPY酷2 小时前
构造与析构:C++ 中对象的温柔生灭
java·jvm·c++
又见野草2 小时前
C++类和对象(下)
开发语言·c++
春夜喜雨2 小时前
关于内存分配的优化与设计
c++·tcmalloc·malloc·jemallc
ae_zr2 小时前
QT动态编译应用后,如何快速获取依赖
开发语言·qt
范纹杉想快点毕业3 小时前
状态机设计与嵌入式系统开发完整指南从面向过程到面向对象,从理论到实践的全面解析
linux·服务器·数据库·c++·算法·mongodb·mfc