码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • QML自定义电池状进度条


    效果:
    在这里插入图片描述
    百分比显示保留两位小数,通过iValue的数值来显示当前进度,注意为了保留小数总值取的是10000,所以你的iValue值也要乘上100

    变量说明:
    cBorderColor:进度条外框的颜色
    cContentColor:表示进度的小方块颜色
    cTextColor:显示进度百分比的文字颜色
    iValue:当前进度,为整数(记得放大100倍)
    iModel:表示进度小方块的数量,该控件的长度与此有关,无需再次设置

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    import QtGraphicalEffects 1.0
    import QtQuick.Layouts 1.3
    
    Rectangle{
        property color cBorderColor: "gray"
        property color cContentColor: "#00cc00"
        property color cTextColor: "black"
        property int iModel: 20
        readonly property int iEndValue: 10000
        readonly property int iStartValue: 0
        property int iValue: 657
        width: iModel * 12 + 4
        height: 33
        color: "transparent"
        Rectangle{
            id:background
            color: "transparent"
            width: iModel * 12 + 4
            height: 20
            border.color: cBorderColor
            Repeater{
                model:iModel
                Rectangle{
                    visible: (index / iModel) < (iValue / iEndValue)
                    x: 2 + index * (width + 2)
                    y: 2
                    width: 10
                    height: background.height - 2 * y
                    color: cContentColor
                }
            }
            Text{
                anchors.top:parent.bottom
                anchors.topMargin: 2
                anchors.left: parent.left
                anchors.right: parent.right
                text:(iValue / iEndValue * 100).toFixed(2) + "%"
                height:10
                horizontalAlignment: Text.AlignHCenter
                color: cTextColor
                font.pixelSize: 12
                font.bold: true
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
  • 相关阅读:
    MQTT服务采用nginx 代理TLS配置
    ChatGPT聊YOLO
    saas多用户小程序商城源码
    AtCoder Beginner Contest 279 F BOX 并查集 (大意失荆州
    Python表格处理模块xlrd在Anaconda中的安装
    阿洛迷茫后的思考
    性能测试高阶内容:了解TPS和RT之间关系
    LLM系列 | 20 : Llama2 实战(下篇)-中文语料微调(附完整代码)
    字符串转数字, 数字转字符串
    BSN长话短说之十:如何保证NFT的安全
  • 原文地址:https://blog.csdn.net/qq_40950183/article/details/134022004
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号