QML —— TabView示例(附完整源码)

示例效果

在这里插入图片描述

TabView介绍

     TabView为应用程序提供了基于选项卡的导航模型。

源码

     TabTest.qml

import QtQuick 2.0

import QtQuick.Layouts 1.12

Item
{
    GridLayout
    {
        anchors.centerIn: parent
        columns: 2
        rowSpacing: 20
        columnSpacing: 20

        Text
        {
            color:"white"
            text: qsTr("输入数量:")
            font.family: "微软雅黑"
            font.pixelSize: 18
        }

        Rectangle
        {
            width: 150
            height: 25
            border.color: "white"
            clip: true
            TextInput
            {
                id: textID
                anchors.fill: parent
                anchors.centerIn: parent
                font.family: "微软雅黑"
                font.pixelSize: 14
                selectByMouse: true
                verticalAlignment:TextInput.AlignVCenter
                horizontalAlignment: TextInput.AlignLeft
            }
        }

        Text
        {
            color:"white"
            text: qsTr("输入长度:")
            font.family: "微软雅黑"
            font.pixelSize: 18
        }

        Rectangle
        {
            width: 150
            height: 25
            border.color: "white"
            clip: true
            TextInput
            {
                id: lengthID
                anchors.fill: parent
                anchors.centerIn: parent
                font.family: "微软雅黑"
                font.pixelSize: 14
                selectByMouse: true
                verticalAlignment:TextInput.AlignVCenter
                horizontalAlignment: TextInput.AlignLeft
            }
        }
    }
}


     main.qml

import QtQuick 2.12
import QtQuick.Window 2.12

import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4

Window
{
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    // 基于选项卡的导航模型
    TabView
    {
        anchors.fill: parent

        style: TabViewStyle
        {
            frameOverlap: 1                 // 此属性保留各个选项卡按钮和框架之间的重叠量
            tabsAlignment: Qt.AlignHCenter  // 选项卡按钮的水平对齐方式(默认左侧)
            tab: Rectangle
            {
                color: styleData.selected ? "gray" :"white"
                border.color: "orange"
                implicitWidth: Math.max(text.width + 4, 100)
                implicitHeight: 40
                radius: 5
                Text
                {
                    id: text
                    anchors.centerIn: parent
                    text: styleData.title
                    color: styleData.selected ? "white" : "black"
                }
            }
            frame: Rectangle { color: "steelblue" }
        }

        // 选项卡
        Tab
        {
            title: qsTr("周一")
            Rectangle{color: "green"}
        }

        Tab
        {
            title: qsTr("周二")
            TabTest{id: tabqmlID}		// 加载TabTest.qml,作为该Tab页内容
        }

        Tab
        {
            title: qsTr("周三")
            Rectangle{color: "pink"}
        }
    }

}

关注

笔者 - jxd

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

信必诺

嗨,支持下哥们呗。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值