【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
                }
            }
        }
    }
相关推荐
我是慎独18 分钟前
VulkanSceneGraph学习教程(十一)
c++·学习
stolentime43 分钟前
AT_agc066_a [AGC066A] Adjacent Difference题解
c++·算法·贪心算法·构造
程序猿编码1 小时前
不用PyTorch,我用C++手写了一个能认手写数字的神经网络
c++·pytorch·神经网络·大模型
不会代码的小猴1 小时前
4. 控件学习2
开发语言·c++·笔记·qt
我是小灰灰吖1 小时前
解决高频率图像处理中的内存“只增不减”:glibc malloc_trim实战指南
linux·qt
闻道且行之2 小时前
图片处理助手|C++ 手搓离线 AI 抠图工具,U2Net 原理到落地一次讲透
开发语言·c++·人工智能·神经网络·opencv·计算机视觉
玖釉-2 小时前
nvpro_core2 源码与架构解析:NVIDIA Vulkan 图形开发基础框架
c++·windows·图形渲染
秋田君2 小时前
QT_一个UDP通信程序(单播+广播)
开发语言·qt·udp
我是小灰灰吖2 小时前
Qt 6.9.3 Ubuntu 22.04 虚拟键盘显示问题全记录与解决方案
linux·qt·ubuntu
啦啦啦啦啦zzzz3 小时前
高级I/O函数(一)
linux·服务器·网络·c++·网络编程