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

        }
相关推荐
ssshooter1 小时前
Tauri 项目实践:客户端与 Web 端的授权登录实现方案
前端·后端·rust
兆子龙1 小时前
【React】19 深度解析:掌握新一代 React 特性
前端·架构
Moment2 小时前
MinIO已死,MinIO万岁
前端·后端·github
无双_Joney2 小时前
心路散文 - 转职遇到AI浪潮,AIGC时刻人的价值是什么?
前端·后端·架构
有意义2 小时前
深度拆解分割等和子集:一维DP数组与倒序遍历的本质
前端·算法·面试
小怪点点2 小时前
vue3使用
前端·vue.js
进击的尘埃2 小时前
Vitest 自定义 Reporter 与覆盖率卡口:在 Monorepo 里搞增量覆盖率检测
javascript
进击的尘埃2 小时前
E2E 测试里的网络层,到底该怎么 Mock?
javascript
Bigger3 小时前
CSS 这些年都经历了什么?一次看懂 CSS 的演化史
前端·css·前端工程化
DevUI团队3 小时前
🚀 【Angular】MateChat V20.2.2版本发布,新增8+组件,欢迎体验~
前端·javascript·人工智能