• QML定时器


    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       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 }
  • 相关阅读:
    并发编程之进程池,线程池 和 异步回调,协程
    form与modeform
    5个_meta方法
    CRM项目知识预备
    Jason数据库查询语句
    kindeditor编辑器
    几种单例模式
    BBS项目复习
    BBS项目小组件
    BBS项目附加知识
  • 原文地址:https://www.cnblogs.com/xiaomanon/p/4546515.html
Copyright © 2020-2023  润新知