File tree Expand file tree Collapse file tree 8 files changed +150
-0
lines changed Expand file tree Collapse file tree 8 files changed +150
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ <RCC>
2
+ <qresource prefix="/">
3
+ <file>main.qml</file>
4
+ <file>QmlProgress.qml</file>
5
+ </qresource>
6
+ </RCC>
Original file line number Diff line number Diff line change @@ -30,3 +30,4 @@ SUBDIRS += QmlCircularProgress
30
30
SUBDIRS += QmlFontList
31
31
SUBDIRS += QmlFlipImage
32
32
SUBDIRS += QmlGrayImage
33
+ SUBDIRS += QmlProgress
Original file line number Diff line number Diff line change @@ -132,3 +132,8 @@ QmlGrayImage: Qml图片转灰度
132
132
133
133
![ ] ( https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlGrayImage/show.jpg?raw=true )
134
134
135
+
136
+ QmlProgress: Qml进度条
137
+
138
+ ![ ] ( https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlProgress/show.gif?raw=true )
139
+
You can’t perform that action at this time.
0 commit comments