码迷,mamicode.com
首页 > 其他好文 > 详细

QML定时器

时间:2015-06-02 17:31:02      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

QML中的定时器能够周期性的触发一个事件,其使用非常简单、方便。这里给出一个示例:

 1 import QtQuick 2.4
 2 import QtQuick.Controls 1.3
 3 import QtQuick.Window 2.2
 4 import QtQuick.Dialogs 1.2
 5 
 6 Rectangle{
 7     id: root
 8     width:  512
 9     height: 512
10     color: "gray"
11 
12     QtObject {
13         id: attrs
14         property int count;
15         Component.onCompleted: {
16             attrs.count = 10;
17         }
18     }
19 
20     Text {
21         id: countShow
22         color: "blue"
23         font.pixelSize: 30
24         anchors.centerIn: parent
25     }
26 
27     Timer {
28         id: countDown
29         interval: 1000
30         repeat: true
31         triggeredOnStart: true
32         onTriggered: {
33             countShow.text = attrs.count;
34             attrs.count -= 1;
35             if (attrs.count < 0){
36                 countDown.stop();
37                 countShow.text = "Clap Now!";
38                 startBtn.text = "Start"
39             }
40         }
41     }
42 
43     Button {
44         id: startBtn
45         text: "Start"
46         onClicked: {
47             attrs.count = 10;
48             countDown.start();
49             startBtn.text = "Restart"
50         }
51 
52         anchors.horizontalCenter: parent.horizontalCenter
53         anchors.bottom: parent.bottom
54         anchors.bottomMargin: 20
55     }
56 }

 

QML定时器

标签:

原文地址:http://www.cnblogs.com/xiaomanon/p/4546515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!