QT QML 界面设计教程3——选项卡样式

MyTabBar.xml

javascript 复制代码
import QtQuick 2.14
import QtQuick.Templates 2.14 as Template1

Template1.TabBar {
    id: control

    property color backgroundColor: "#36c588"
    property color borderColor: "grey"

    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                            contentWidth + leftPadding + rightPadding)
    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                             contentHeight + topPadding + bottomPadding)

    spacing: 1

    contentItem: ListView {
        model: control.contentModel
        currentIndex: control.currentIndex

        spacing: control.spacing
        orientation: ListView.Horizontal
        boundsBehavior: Flickable.StopAtBounds
        flickableDirection: Flickable.AutoFlickIfNeeded
        snapMode: ListView.SnapToItem

        highlightMoveDuration: 0
        highlightRangeMode: ListView.ApplyRange
        preferredHighlightBegin: 40
        preferredHighlightEnd: width - 40
    }

    background: Rectangle {
        implicitHeight: 30
        color: control.backgroundColor

        Rectangle {
            color: control.borderColor
            width: parent.width
            height: 1
            anchors.bottom: parent.bottom
        }
    }
}

调用:

javascript 复制代码
        MyTabBar{
            id: tabNavigator
            x: 200
            y: -11
            width: 800

            //tabbar默认平均分宽度
            MyTabButton{
                x: 0
                y: 0
                width: 120

                text:qsTr("选项一")
                font.preferShaping: false
                wheelEnabled: false
                font.kerning: false


                onClicked:
                {
                       //leftPanel.show();
                       toolBarPatient.visible=true;
                       toolBarScanner.visible=false;
                       toolBarImpantView.visible=false;
                       toolBarConsult.visible=false;
                       toolBarReport.visible=false;
                       patientTab.visible=true;
                       scannerTab.visible=false;
                       implantTab.visible=false;
                       consultTab.visible=false;
                       reportTab.visible=false;
                }
            }
            MyTabButton{
                x: 0
                y: 0
                width: 120

                text:qsTr("选项二")
                onClicked:
                {
                       //leftPanel.show();
                       toolBarPatient.visible=false;
                       toolBarScanner.visible=true;
                       toolBarImpantView.visible=false;
                       toolBarConsult.visible=false;
                       toolBarReport.visible=false;
                       patientTab.visible=false;
                       scannerTab.visible=true;
                       implantTab.visible=false;
                       consultTab.visible=false;
                       reportTab.visible=false;
                }
            }
      
         

        }
相关推荐
哎呦你好9 分钟前
【CSS】Grid 布局基础知识及实例展示
开发语言·前端·css·css3
盛夏绽放18 分钟前
接口验证机制在Token认证中的关键作用与优化实践
前端·node.js·有问必答
zhangxingchao34 分钟前
Jetpack Compose 之 Modifier(中)
前端
JarvanMo34 分钟前
理解 Flutter 中 GoRouter 的context.push与context.go
前端
pe7er40 分钟前
使用 Vue 官方脚手架创建项目时遇到 Node 18 报错问题的排查与解决
前端·javascript·vue.js
星始流年43 分钟前
前端视角下认识AI Agent
前端·agent·ai编程
pe7er1 小时前
使用 types / typings 实现全局 TypeScript 类型定义,无需 import/export
前端·javascript·vue.js
CH_Qing1 小时前
【udev】关于/dev 设备节点的生成 &udev
linux·前端·网络
小诸葛的博客1 小时前
gin如何返回html
前端·html·gin
islandzzzz1 小时前
(第二篇)HMTL+CSS+JS-新手小白循序渐进案例入门
前端·javascript·css·html