当前位置: 首页 > article >正文

Qt/QML学习-CircularGauge

QML学习

  • CircularGauge例程
  • 视频讲解
  • 代码

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Extras 1.4
import QtQuick.Controls.Styles 1.4

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    CircularGauge {
        id: circularGauge
        anchors.fill: parent
        anchors.centerIn: parent
        minimumValue: 0
        maximumValue: 100
        value: 50
        stepSize: 0.1
        tickmarksVisible: true

        // 自定义样式
        style: CircularGaugeStyle {
            id: style

            // 背景
            background: Rectangle {
                radius: outerRadius
                color: "black"
                border.width: 1
                border.color: "LightGray"
                Text {
                    anchors.top: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
                    topPadding: parent.radius / 5
                    color: "white"
                    text: "关注:" + control.value
                    font {
                        pointSize: topPadding / 1.5 > 0? topPadding / 1.5: 1
                        bold: true
                    }
                }
            }

            // 大刻度
            tickmark: Rectangle {
                implicitWidth: outerRadius * 0.04
                implicitHeight: outerRadius * 0.08
                antialiasing: true
                color: styleData.value >= 80 ? "red" : "white"
            }

            // 小刻度
            minorTickmark: Rectangle {
                implicitWidth: outerRadius * 0.01
                implicitHeight: outerRadius * 0.03
                antialiasing: true
                color: styleData.value >= 80 ? "red" : "white"
            }

            // 刻度文本
            tickmarkLabel:  Text {
                font.pixelSize: Math.max(6, outerRadius * 0.1)
                text: styleData.value
                antialiasing: true
                color: styleData.value >= 80 ? "red" : "white"
            }

            // 指针
            needle: Rectangle {
                y: outerRadius * 0.15
                implicitWidth: outerRadius * 0.03
                implicitHeight: outerRadius * 0.9
                antialiasing: true
                color: "orangered"
            }

            // 前景
            foreground: Item {
                Rectangle {
                    width: outerRadius * 0.2
                    height: width
                    radius: width / 2
                    color: "orangered"
                    anchors.centerIn: parent
                }
            }

            // 刻度文本到外半径的距离
            labelInset: outerRadius * 0.25

            // 小刻度到外半径的距离
            minorTickmarkInset: outerRadius * 0.1

            // 大刻度到外半径的距离
            tickmarkInset: outerRadius * 0.05

            // 最小刻度角度位置
            minimumValueAngle: -180

            // 最大刻度角度位置
            maximumValueAngle: 90
        }
    }
    // 演示
    Timer {
        interval: 20
        repeat: true
        running: true
        onTriggered: {
            if (circularGauge.value ++ >= circularGauge.maximumValue) {
                circularGauge.value = circularGauge.minimumValue
            }
        }
    }
}

演示

视频讲解


http://www.kler.cn/news/292628.html

相关文章:

  • Python函数的编写
  • 上海市计算机学会竞赛平台2024年8月月赛丙组调和级数
  • CMU 10423 Generative AI:HW0
  • 【计算机网络】socket编程 几个网络命令
  • 【机器学习】Boosting与Bagging算法
  • 哈希扩展(位图与布隆过滤器)
  • React基础教程(09):react的属性介绍(props)
  • 万界星空科技MES:企业实现数字化转型的护航者
  • SpringCloud之CircuitBreaker
  • 江协科技stm32————10-5 硬件I2C读写MPU6050
  • 宝扬笔记本电脑重做win10系统教程
  • 2024国赛数学建模C题完整论文:农作物的种植策略
  • 智 能 合 约
  • 【css】获取最后一个li进行样式特殊处理
  • 企微获客链接 中文乱码问题处理
  • 高德地图根据经纬度获取详细地址
  • RK3588开发板利用udp发送和接收数据
  • pyro ExponentialLR 如何设置优化器 optimizer的学习率 pytorch 深度神经网络 bnn,
  • JavaScript 21个常用数组使用方法
  • Linux运维--Firewall防火墙命令以及规则等详解(全)
  • 针对不同区域的摄像头,完成不同的算法配置的智慧快消开源了
  • PostgreSQL技术内幕7:PostgreSQL查询编译
  • SpringBoot 消息队列RabbitMQ Work模型 绑定多个消费者 负载均衡 消息处理速度
  • 学习记录:js算法(二十五):合并两个有序链表
  • Power Automate向Power Apps传Table数据
  • C++项目引入开源库bit7z
  • ARM SIMD instruction -- movi
  • ccfcsp-202209(1、2、3)
  • Kafka【十一】数据一致性与高水位(HW :High Watermark)机制
  • 企业财务流程优化的财税自动化解决方案