QT自定义进度条ProgressBar
来源:互联网 发布:mac os系统下载百度云 编辑:程序博客网 时间:2024/05/17 05:08
自定义进度条
效果图:
QML源码
ProgressBar.qml
import QtQuick 2.0Item{//滑动条 id:root property string bgSource: "" property string fgSource: "" property string thumbSource: "" property real currentValue: 50 //当前值 property real max: 100 property real min: 0 property real thumbStartPosX: 0 //进度按钮相对背景的位置 property int touchHeightMin: 48//最小触摸高度 property alias thumbPosX: thumb.x property alias mouseAreaEnabled :rootArea.enabled signal seek(real offset,bool pressed); implicitHeight: thumb.height > bg.height ? thumb.height : bg.height implicitWidth: thumbStartPosX < 0?bg.width - thumbStartPosX*2:bg.width //私有属性,这些值只是方便使用 QtObject{ id:privateValue; property real percent:(max-min)>0?(currentValue-min)/(max-min):0 property real moveDistanceMax: bg.width - thumbStartPosX*2 - thumb.width property real moveDistanceMin: bg.x + thumbStartPosX property real currentMoveDistance:moveDistanceMax*percent// onPercentChanged: {// updateProgress();// } } //直接使用onPercentChanged会导致thumb.x初始化的值设置不成功, //因为初始化时onPercentChanged会触发 // onCurrentValueChanged: { updateProgress(); } onMaxChanged: { updateProgress(); } onMinChanged: { updateProgress(); } Component.onCompleted: { //console.log(" Component.onCompleted ") updateProgress(); } Image{ id:bg anchors.centerIn: parent source: bgSource } Image{ id:fg anchors.top:bg.top anchors.left:bg.left width:thumb.x height:bg.height source:fgSource fillMode: Image.PreserveAspectCrop horizontalAlignment :Image.AlignLeft verticalAlignment: Image.AlignBottom clip: true } Image{ id:thumb anchors.verticalCenter: parent.verticalCenter x:privateValue.currentMoveDistance source:thumbSource } MouseArea{ id: rootArea anchors.centerIn: parent width: root.width height: root.height < touchHeightMin ? touchHeightMin : root.height drag.maximumX: privateValue.moveDistanceMax drag.minimumX: privateValue.moveDistanceMin drag.target: thumb //hoverEnabled: true onPressed: { if(mouseX - thumb.width/2>=drag.minimumX &&mouseX - thumb.width/2<=drag.maximumX){ thumb.x = mouseX - thumb.width/2; }else if(mouseX - thumb.width/2<drag.minimumX) { thumb.x = drag.minimumX; }else if(mouseX - thumb.width/2>drag.maximumX){ thumb.x = drag.maximumX; } } onPositionChanged: { returnVal(true); } onReleased: { //返回值,刷新进度条 returnVal(false); //console.log("onReleased") //updateProgress(); } } function returnVal(pressed ){ var step = max-min; var offset = 0; if(privateValue.moveDistanceMax-privateValue.moveDistanceMin>0) { offset = (thumb.x)/(privateValue.moveDistanceMax-privateValue.moveDistanceMin) *step+min; root.seek(offset,pressed); } } function updateProgress(){ if(!rootArea.pressed) { privateValue.percent =(max-min)>0?(currentValue-min)/(max-min):0; //console.log("privateValue.percent = "+privateValue.percent) //console.log("bg.width = "+bg.width) //console.log("thumbStartPosX= "+thumbStartPosX) //console.log("thumb.width = "+thumb.width) if(privateValue.percent > 0) { if(privateValue.percent<=1) { thumb.x = (bg.width - thumbStartPosX*2 - thumb.width)*privateValue.percent; } else if(privateValue.percent > 1) { thumb.x =privateValue.moveDistanceMax; } else { thumb.x = 0; } } else { thumb.x = 0 } } // fg.width = thumb.x //console.log("thumb.x = "+thumb.x) }}
阅读全文
0 0
- QT自定义进度条ProgressBar
- 自定义进度条ProgressBar
- 自定义progressBar(进度条)
- 自定义进度条(ProgressBar)
- 自定义圆形进度条 progressBar
- 自定义progressbar进度条颜色
- 自定义ProgressBar进度条
- 自定义progressbar进度条颜色
- 自定义进度条样式progressBar
- 自定义 ProgressBar 进度条 自定义样式
- 自定义 ProgressBar 进度条 自定义样式
- android ProgressBar 自定义进度条颜色
- 自定义View之-ProgressBar进度条
- android ProgressBar 实现自定义进度条
- 自定义水平进度条Horizontal ProgressBar
- 自定义进度条ProgressBar的实现
- Android 各种自定义进度条Progressbar
- 自定义ProgressBar实现圆弧进度条
- JavaFx入门教程(二)
- 单一职责原则
- 属性word-wrap与word-break的区别
- spring整合session出现问题
- 【源代码扫描工具-fortify SCA】-第一部:原理简介
- QT自定义进度条ProgressBar
- spring集成 JedisCluster 连接 redis3.0 集群
- tensorflow1.1/激活函数可视化
- 使用TextRank算法为文本生成关键字和摘要
- POJ-tarjan-强连通分量+缩点-Popular Cows
- 6.29 LL--实习日志--Restful API 概念理解+Restful_API编写
- Python构造包含中英文的字符串
- WMI命名空间详解 subscription DEFAULT MicrosoftDfs CIMV2 Cli nap
- H5 直播避坑指南