Rectangle{
id: root
width: 512
height: 512
color: "gray"
QtObject {
id: attrs
property int count;
Component.onCompleted: {
attrs.count = 10;
}
}
Text {
id: countShow
color: "blue"
font.pixelSize: 30
anchors.centerIn: parent
}
Timer {
id: countDown
interval: 1000
repeat: true
triggeredOnStart: true
onTriggered: {
countShow.text = attrs.count;
attrs.count -= 1;
if (attrs.count < 0){
countDown.stop();
countShow.text = "Clap Now!";
startBtn.text = "Start"
}
}
}
Button {
id: startBtn
text: "Start"
onClicked: {
attrs.count = 10;
countDown.start();
startBtn.text = "Restart"
}
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
}
}
QML实现倒计时功能
最新推荐文章于 2023-09-19 23:02:39 发布