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;
                }
            }
      
         

        }
相关推荐
2501_915918411 小时前
Web 前端可视化开发工具对比 低代码平台、可视化搭建工具、前端可视化编辑器与在线可视化开发环境的实战分析
前端·低代码·ios·小程序·uni-app·编辑器·iphone
程序员的世界你不懂2 小时前
【Flask】测试平台开发,新增说明书编写和展示功能 第二十三篇
java·前端·数据库
索迪迈科技2 小时前
网络请求库——Axios库深度解析
前端·网络·vue.js·北京百思可瑞教育·百思可瑞教育
gnip2 小时前
JavaScript二叉树相关概念
前端
一朵梨花压海棠go2 小时前
html+js实现表格本地筛选
开发语言·javascript·html·ecmascript
attitude.x3 小时前
PyTorch 动态图的灵活性与实用技巧
前端·人工智能·深度学习
β添砖java3 小时前
CSS3核心技术
前端·css·css3
空山新雨(大队长)3 小时前
HTML第八课:HTML4和HTML5的区别
前端·html·html5
猫头虎-前端技术3 小时前
浏览器兼容性问题全解:CSS 前缀、Grid/Flex 布局兼容方案与跨浏览器调试技巧
前端·css·node.js·bootstrap·ecmascript·css3·媒体