6.4.2 倒计时
。
/**********************
6.4.2 倒计时
***********************/
import QtQuick 2.2
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.1
Window {
visible: true
width: 640
height: 240
minimumWidth: 960
minimumHeight: 760
QtObject{
id:attrs
property int counter
Component.onCompleted: {
attrs.counter = 10
}
}
Text {
id: countshow
anchors.centerIn: parent
color: "blue"
font.pixelSize: 40
}
Timer{
id:countDown
interval: 100
repeat: true
triggeredOnStart: true
onTriggered: {
countshow.text = attrs.counter
attrs.counter -= 1
if(attrs.counter < 0 ){
countDown.stop()
countshow.text = "clap now"
}
}
}
Button{
id:startButton
text: "start"
anchors.left: parent.left
anchors.leftMargin: 16
anchors.bottom: parent.bottom
anchors.bottomMargin: 16
style:ButtonStyle{
background: Rectangle{
implicitWidth: 140
implicitHeight: 50
color: "red"
border.width: 2
border.color: "green"
}
}
onClicked: {
attrs.counter = 10
countDown.start()
}
z:4
}
}
。