記錄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();
}
}
}