【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
                }
            }
        }
    }
相关推荐
玖釉-1 小时前
[Vulkan 学习之路] 16 - 最终章:渲染循环与同步 (Rendering & Presentation)
c++·windows·图形渲染
狗狗学不会2 小时前
Pybind11 封装 RK3588 全流程服务:Python 写逻辑,C++ 跑并发,性能起飞!
c++·人工智能·python·目标检测
DYS_房东的猫2 小时前
《 C++ 零基础入门教程》第10章:C++20 核心特性 —— 编写更现代、更优雅的 C++
java·c++·c++20
Howrun7772 小时前
虚幻引擎_AController_APlayerController_AAIController
开发语言·c++·游戏引擎·虚幻
小林rr2 小时前
深入探索 C++:现代特性、工程实践与性能优化全解
java·c++·性能优化
羊小猪~~2 小时前
【QT】-- QT基础类
开发语言·c++·后端·stm32·单片机·qt
努力写代码的熊大3 小时前
深入探索C++关联容器:Set、Map、Multiset与Multimap的终极指南及底层实现剖析
开发语言·c++
txinyu的博客3 小时前
Linux 内存管理
linux·运维·开发语言·c++
zzxxlty3 小时前
kafka C++ 和 java端计算分区ID不一致排查
java·c++·kafka
Reenrr3 小时前
C++学习
开发语言·c++·学习