QML的定时器Timer是一个不可视的对象,用法很简单,需要设置的值也很少。
Timer {
id: timer_button;
interval: 500;//设置定时器定时时间为500ms,默认1000ms
repeat: false //是否重复定时,默认为false
running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
onTriggered: {button.color = "green" //定时触发槽,定时完成一次就进入一次
}
//restart ,start,stop,定时器的调用方式,顾名思义
}
Text {
id: button
anchors.centerIn: parent
text: qsTr("Buton")
font.pixelSize: 45
color: "red"
MouseArea{
anchors.fill: parent
onClicked: timer_button.start(); //开启定时器
}
}
Timer {
id: timer_button;
interval: 500;//设置定时器定时时间为500ms,默认1000ms
repeat: false //是否重复定时,默认为false
running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
onTriggered: {button.color = "green" //定时触发槽,定时完成一次就进入一次
}
//restart ,start,stop,定时器的调用方式,顾名思义
}
Text {
id: button
anchors.centerIn: parent
text: qsTr("Buton")
font.pixelSize: 45
color: "red"
MouseArea{
anchors.fill: parent
onClicked: timer_button.start(); //开启定时器
}
}