QML单选选项卡按钮

在这里插入图片描述
使用到QML图标文字按钮 https://blog.csdn.net/qq_39827640/article/details/130734320

RadioTabButton.qml

import QtQuick
import QtQuick.Controls

TabBar {
  id: control

  height: 32
  width: 290
  spacing: spacing + 0 - 2 * btnMargin

  property alias model: repeater.model
  property real radius: 15
  property real btnMargin: 2
  property real btnIconWidth: 24
  property real btnIconHeight: 24
  property real btnIconLeftMargin: 0
  property real btnIconAndTextSpacing: 2
  property bool btnIsHorizontalCenter: true
  property color bgColor: "#3E3D40"
  property color bgDisabledColor: "#3E3D40"
  property var btnDefaultGradient: Gradient {
    GradientStop { position: 0.0; color: "transparent" }
    GradientStop { position: 1.0; color: "transparent" }
    orientation: Gradient.Horizontal
  }
  property var btnHoverGradient: Gradient {
    GradientStop { position: 0.0; color: "#6C6B6E" }
    GradientStop { position: 1.0; color: "#6C6B6E" }
    orientation: Gradient.Horizontal
  }
  property var btnPressedGradient: Gradient {
    GradientStop { position: 0.0; color: "#875CFF" }
    GradientStop { position: 1.0; color: "#D25CFF" }
    orientation: Gradient.Horizontal
  }
  property var btnCheckedGradient: Gradient {
    GradientStop { position: 0.0; color: "#875CFF" }
    GradientStop { position: 1.0; color: "#D25CFF" }
    orientation: Gradient.Horizontal
  }
  property var btnDisabledGradient: Gradient {
    GradientStop { position: 0.0; color: "transparent" }
    GradientStop { position: 1.0; color: "transparent" }
    orientation: Gradient.Horizontal
  }
  property var btnCheckedHoverGradient: Gradient {
    GradientStop { position: 0.0; color: "#9B76FF" }
    GradientStop { position: 1.0; color: "#DA76FF" }
    orientation: Gradient.Horizontal
  }
  property var btnCheckedPressedGradient: Gradient {
    GradientStop { position: 0.0; color: "#A583FF" }
    GradientStop { position: 1.0; color: "#DC83FF" }
    orientation: Gradient.Horizontal
  }
  property var btnCheckedDisabledGradient: Gradient {
    GradientStop { position: 0.0; color: "#6C6B6E" }
    GradientStop { position: 1.0; color: "#6C6B6E" }
    orientation: Gradient.Horizontal
  }
  property color btnTextDefaultColor: "#A9A9AA"
  property color btnTextHoverColor: "#FFFFFF"
  property color btnTextPressedColor: "#FFFFFF"
  property color btnTextCheckedColor: "#FFFFFF"
  property color btnTextDisabledColor: "#6C6B6E"
  property color btnTextCheckedHoverColor: "#FFFFFF"
  property color btnTextCheckedPressedColor: "#FFFFFF"
  property color btnTextCheckedDisabledColor: "#8F8E91"
  property real btnTextPointSize: 10

  background: Rectangle {
    id: controlBg
    color: enabled ? bgColor : bgDisabledColor
    radius: control.radius
  }

  Repeater {
    id: repeater
    anchors.fill: parent
    model: [
      { text: "Select", icon: "qrc:/qmldemo.com/avkit/assets/anieraser/icon24_restore.png" },
      { text: "DeSelect", icon: "qrc:/qmldemo.com/avkit/assets/anieraser/icon24_erase.png" },
    ]
    TabButton {
      height: parent.height
      anchors.verticalCenter: parent.verticalCenter
      checked: currentIndex === index
      contentItem: IconTextButton {
        anchors.fill: parent
        anchors.margins: btnMargin
        // enabled: control.enabled
        radius: control.radius
        text: modelData.text
        iconsource: modelData.icon
        checked: parent.checked
        isHorizontalCenter: btnIsHorizontalCenter
        defaultGradient: btnDefaultGradient
        hoverGradient: btnHoverGradient
        pressedGradient: btnPressedGradient
        checkedGradient: btnCheckedGradient
        disabledGradient: btnDisabledGradient
        checkedHoverGradient: btnCheckedHoverGradient
        checkedPressedGradient: btnCheckedPressedGradient
        checkedDisabledGradient: btnCheckedDisabledGradient
        textDefaultColor: btnTextDefaultColor
        textHoverColor: btnTextHoverColor
        textPressedColor: btnTextPressedColor
        textCheckedColor: btnTextCheckedColor
        textDisabledColor: btnTextDisabledColor
        textCheckedHoverColor: btnTextCheckedHoverColor
        textCheckedPressedColor: btnTextCheckedPressedColor
        textCheckedDisabledColor: btnTextCheckedDisabledColor
        textPointSize: btnTextPointSize
        iconWidth: btnIconWidth
        iconHeight: btnIconHeight
        iconLeftMargin: btnIconLeftMargin
        iconAndTextSpacing: btnIconAndTextSpacing

        mouseArea {
          enabled: control.enabled
          onPressed: {
            currentIndex = index
          }
        }
      }
      background: Rectangle {
        id: btnBg
        anchors.fill: parent
        color: "transparent"
      }
    }
  }
}

        RadioTabButton {
          model: [
            { text: "Select", icon: "qrc:/qmldemo.com/avkit/assets/anieraser/icon24_restore.png" },
            { text: "DeSelect", icon: "qrc:/qmldemo.com/avkit/assets/anieraser/icon24_erase.png" },
          ]
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值