QtQuick學習筆記之QML定時器Timer

記錄Qtquick核心編程學習筆記:

import QtQuick 2.5
import QtQuick.Controls 1.4
Rectangle{
    width:300;
    height:400;
    id:root;
    color:"green";

    QtObject {
        id:attr;
        property int counter;
        Component.onCompleted: {
            attr.counter = 10;
        }
    }

    Text {
        id: countShow;
        text: qsTr("倒計時");
        anchors.centerIn: parent;
        color: "blue";
        font.pointSize: 24;
    }

    Timer {
        id:countDowm;
        repeat: true;
        interval: 1000;
        triggeredOnStart: true;
        onTriggered: {
            countShow.text = attr.counter;
            attr.counter--;
            if(attr.counter < 0)
            {
                countDowm.stop();
                countShow.text = "Clap Now !";
            }

        }
    }
    Button {
        id :textButton;
        text: "開始";
        anchors.top: countShow.bottom;
        anchors.topMargin: 10;
        anchors.horizontalCenter: parent.horizontalCenter;
        onClicked: {
            attr.counter = 10;
            countDowm.start();
        }
    }
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章