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

        }
相关推荐
量化分析码农17 分钟前
【Python量化多因子实战 04】因子暴露不是 alpha:市值与行业中性化实战
前端·后端
不可能片场1 小时前
Electron 发布 正文写入的三条通道与读回口径
前端·electron
程序员大阳1 小时前
副队长JavaScript教程(66)-本地存储实战:待办事项网页的开发
javascript·json·实战·待办事项·本地存储·案例
jerrywus1 小时前
让 AI 帮你部署 Vercel,报错了也不用手动搬日志
前端·agent·mcp
补码缩写1 小时前
11 行 Python 拆 PNG 块,解压后的字节数能手算
前端
coding漫漫长路1 小时前
PNG压缩先看图是哪一类,先无损再量化多半白做
前端
用户257680763211 小时前
搜「洗牙」为什么搜不到「洁治」
前端
费曼学习法1 小时前
Agent 死循环的根因不在模型:错误分类、退避、熔断、快照四层实现
前端
修炼的dance1 小时前
同一张PNG换五种压法,体积差在颜色数上
前端
Lank_M1 小时前
PNG 有损压缩省下的体积,大头不在 deflate
前端