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

        }
相关推荐
uyeonashi1 小时前
【QT控件】输入类控件详解
开发语言·c++·qt
kite01215 小时前
浏览器工作原理06 [#]渲染流程(下):HTML、CSS和JavaScript是如何变成页面的
javascript·css·html
крон5 小时前
【Auto.js例程】华为备忘录导出到其他手机
开发语言·javascript·智能手机
coding随想8 小时前
JavaScript ES6 解构:优雅提取数据的艺术
前端·javascript·es6
年老体衰按不动键盘8 小时前
快速部署和启动Vue3项目
java·javascript·vue
小小小小宇8 小时前
一个小小的柯里化函数
前端
灵感__idea8 小时前
JavaScript高级程序设计(第5版):无处不在的集合
前端·javascript·程序员
小小小小宇8 小时前
前端双Token机制无感刷新
前端
小小小小宇8 小时前
重提React闭包陷阱
前端
小小小小宇8 小时前
前端XSS和CSRF以及CSP
前端