qml 自定义渐变色进度条样式

本博客仅用于记录qml中渐变间隔块状样式进度条的实现,creator本版:5.7.0
颜色渐变通过gradient实现,块状间隔样式通过OpacityMask实现。
如图:
在这里插入图片描述
动态进度展示:
在这里插入图片描述
qml实现代码:

import QtQuick 2.6
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0

Item{
    id:control
    property var value: 0.0//进度值 范围0.0~1.0
    property var bar_w:24//块状宽度
    property var _radius:2//块状圆角
    Item{
        id:id_item1
        anchors.fill: parent
        visible: false
        Rectangle{
            id:id_rect1
            anchors.centerIn: parent
            width: parent.height
            height: parent.width
            rotation: -90
            gradient: Gradient {
                GradientStop {
                    position: 0.0
                    color: "#35b992"
                }
                GradientStop {
                    position: 0.5
                    color: "#cdbf42"
                }
                GradientStop {
                    position: 1.0
                    color: "#f03737"
                }
            }
        }
        Rectangle{
            anchors{
                right: parent.right
                top: parent.top
                bottom: parent.bottom
            }
            width: parent.width * (1.0 - value)
            color:"#DFDFDF"
        }
    }

    Rectangle{
        id:id_mask
        anchors.fill: parent
        visible: false
        antialiasing: true
        smooth: true
        color: "transparent"
        Row {
            id:id_row
            anchors.fill: parent
            anchors.leftMargin: 10
            Repeater {
                model: id_row.width/bar_w
                delegate: Item {
                    width: bar_w
                    height: id_row.height+20
                    rotation: 15
                    Rectangle{
                        anchors.fill: parent
                        anchors.rightMargin: parent.width/2
                        radius: _radius
                    }
                    Item {
                        anchors.fill: parent
                        anchors.leftMargin: parent.width/2
                    }
                }
            }
        }
    }
    OpacityMask {
        id:mask_image
        anchors.left: id_item1.left
        anchors.verticalCenter: id_item1.verticalCenter
        width: id_mask.width
        height: id_item1.height
        source: id_item1
        maskSource: id_mask
        visible: true
        antialiasing: true
    }
}

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值