Skip to content

Timer

This example shows a timer that counts down from 10 to 0 every second:

import { Button } from "std-widgets.slint";
export component Example inherits Window {
property <int> value: 10;
timer := Timer {
interval: 1s;
running: true;
triggered() => {
value -= 1;
if (value == 0) {
self.running = false;
}
}
}
HorizontalLayout {
Text { text: value; }
Button {
text: "Reset";
clicked() => { value = 10; timer.running = true; }
}
}
}

Use the Timer pseudo-element to schedule a callback at a given interval. The timer is only running when the running property is set to true. To stop or start the timer, set that property to true or false. It can be also set to a binding expression. When already running, the timer will be restarted if the interval property is changed.

interval

type: duration
default: 0ms

The interval between timer ticks. This property is mandatory.

running

type: bool
default: true

true if the timer is running. (default value: true)

Callbacks

triggered()

Invoked every time the timer ticks (every interval).