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

Qt/QML学习-Dial

QML学习

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

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("Hello World")Dial {anchors.fill: parentid: dial// 设置旋钮的范围from: 0to: 100// 设置旋钮的初始值value: 50// 设置旋钮的步长stepSize: 0.1// 监听旋钮值变化的信号onValueChanged: {label.text = value.toFixed(1);}// 计算弧度property real angleInRadian: (dial.angle * Math.PI) / 180// 背景视图以中心为原点(0, 0)来计算,(0, radius)是初始坐标property real coeff: 30// 计算旋转后的坐标property real angleX: - (backgroundRect.radius - coeff) * Math.sin(angleInRadian)property real angleY: (backgroundRect.radius - coeff) * Math.cos(angleInRadian)// 绘制手柄handle: Rectangle {radius: 0width: dial.coeffheight: dial.coeffcolor: "transparent"border.width: 1x: parent.width / 2 - parent.angleX - (width / 2)y: parent.height / 2 - parent.angleY - (height / 2)rotation: dial.angle}// 绘制背景background: Rectangle {id: backgroundRectradius: (dial.width > dial.height)? (dial.height / 2): (dial.width / 2)width: radius * 2height: radius * 2anchors.centerIn: dialcolor: "transparent"border.width: 1Canvas {anchors.fill: parentonPaint: {draw()}function draw() {var ctx = getContext("2d")// 绘制背景ctx.clearRect(0, 0, width, height)// 背景动态与角度绑定ctx.beginPath();ctx.arc(width / 2, height / 2,backgroundRect.radius - dial.coeff,(-140 - 90) * Math.PI / 180,(dial.angle - 90) * Math.PI / 180, false);ctx.stroke();requestAnimationFrame(draw)}}}// 中心位置显示数值Label {id: labeltext: "0"font.bold: truefont.pixelSize: 30anchors.centerIn: parent}}
}

演示

视频讲解

http://www.lryc.cn/news/425734.html

相关文章:

  • 达梦数据库系列—48.DMHS实现Mysql到DM8的同步
  • PostgreSQL的启动过程
  • ActiveMQ、RabbitMQ、Kafka、RocketMQ的区别简介
  • 7.1 多态案例
  • 革新测试管理:集远程、协同、自动化于一身的统一测试管理平台
  • HAProxy的详解
  • 网络安全实训第一天(dami靶场搭建,XSS、CSRF、模板、任意文件删除添加、框架、密码爆破漏洞)
  • 4.1 SQL的起源与发展
  • android中实现禁掉有线网络
  • docker-compose安装MongoDB 7.0.12
  • Ubuntu下NFS和SSH服务
  • 游戏管理系统
  • 坐牢第二十七天(聊天室)
  • C++自学笔记33(数据类型总结与变量)
  • 游戏引擎phaser.js3的使用之玩家和静态物理组碰撞
  • springboot整合mybatis以及mybatis-plus 开发
  • 大语言模型微调框架Unsloth:简化模型微调流程,提升模型性能
  • IPD-华为研发之道分析与理解
  • 时空序列顶会文章
  • C语言-使用指针数组作为函数参数,实现对10个字符串进行排序
  • ???ABC366:F - Maximum Composition(dp,无序:贪心排序)
  • unity项目打包为webgl后应用于vue项目中(iframe模式)的数据交互
  • 【数据结构与算法 | 图篇】Bellman-Ford算法(单源最短路径算法)
  • Python | Leetcode Python题解之第336题回文对
  • C语言家教记录(六)
  • C++竞赛初阶L1-11-第五单元-for循环(25~26课)519: T454430 人口增长问题
  • demo测试
  • TinTinLand Web3 + DePIN 共学月|深入探索 DePIN 项目,全景分析去中心化网络未来
  • Java并发编程(六)
  • k8s对外服务之Ingress