Skip to content

Commit e9b97da

Browse files
committed
Add QmlProgress
1 parent 7e54f37 commit e9b97da

File tree

8 files changed

+150
-0
lines changed

8 files changed

+150
-0
lines changed

QmlProgress/QmlProgress.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlProgress/QmlProgress.qml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*!
2+
*@file QmlProgress.qml
3+
*@brief Qml进度条
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.2
10+
11+
ProgressBar {
12+
property color proColor: "#148014"
13+
property color proBackgroundColor: "#AAAAAA"
14+
property int proWidth: 2
15+
property real progress: 0
16+
property real proRadius: 3
17+
property alias interval: timer.interval
18+
19+
function isRunning(){
20+
return(timer.running)
21+
}
22+
23+
function onStart(){
24+
cProgress.progress = 0;
25+
timer.running = true;
26+
}
27+
28+
function onStop(){
29+
timer.running = false;
30+
}
31+
32+
id: cProgress
33+
anchors.centerIn: parent
34+
value: (progress/100)
35+
padding: 2
36+
37+
background: Rectangle {
38+
implicitWidth: 200
39+
implicitHeight: 16
40+
color: cProgress.proBackgroundColor
41+
radius: cProgress.proRadius
42+
}
43+
44+
contentItem: Item {
45+
implicitWidth: 200
46+
implicitHeight: 10
47+
48+
Rectangle {
49+
width: cProgress.visualPosition * parent.width
50+
height: parent.height
51+
radius: 2
52+
color: cProgress.proColor
53+
}
54+
}
55+
56+
Timer{
57+
id: timer
58+
running: false
59+
repeat: true
60+
interval: 50
61+
onTriggered:{
62+
cProgress.progress++;
63+
if (cProgress.progress > 100){
64+
cProgress.onStop();
65+
return;
66+
}
67+
}
68+
}
69+
}

QmlProgress/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlProgress/main.qml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.2
10+
11+
ApplicationWindow {
12+
visible: true
13+
width: 400
14+
height: 300
15+
title: qsTr("Qml进度条")
16+
17+
QmlProgress {
18+
id: cProgress
19+
anchors.centerIn: parent
20+
}
21+
22+
Button{
23+
id: btnStart
24+
anchors.horizontalCenter: cProgress.horizontalCenter
25+
anchors.top: cProgress.bottom
26+
anchors.topMargin: 6
27+
text: cProgress.isRunning() ? qsTr("结束") : qsTr("开始")
28+
onClicked: {
29+
if (cProgress.isRunning()){
30+
cProgress.onStop();
31+
}else{
32+
cProgress.onStart();
33+
}
34+
}
35+
}
36+
}

QmlProgress/qml.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>QmlProgress.qml</file>
5+
</qresource>
6+
</RCC>

QmlProgress/show.gif

88.3 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ SUBDIRS += QmlCircularProgress
3030
SUBDIRS += QmlFontList
3131
SUBDIRS += QmlFlipImage
3232
SUBDIRS += QmlGrayImage
33+
SUBDIRS += QmlProgress

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ QmlGrayImage: Qml图片转灰度
132132

133133
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlGrayImage/show.jpg?raw=true)
134134

135+
136+
QmlProgress: Qml进度条
137+
138+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlProgress/show.gif?raw=true)
139+

0 commit comments

Comments
 (0)