使用时间选择器选择时间,支持 24 小时制或 12 小时制(AM/PM)。
slint
import { TimePickerPopup, Button } from "std-widgets.slint";export component Example inherits Window { width: 400px; height: 600px;
time-picker-button := Button { text: @tr("Open TimePicker");
clicked => { time-picker.show(); } }
time-picker := TimePickerPopup { x: (root.width - self.width) / 2; y: (root.height - self.height ) / 2; width: 360px; height: 524px; canceled => { time-picker.close(); }
accepted(time) => { debug(time); time-picker.close(); } }}
属性
use-24-hour-format
bool 默认:system default
如果设置为 true,则以 24 小时制显示,否则以 AM/PM 模式显示。(默认值:系统默认值,如果无法确定则为 true)
title
string 默认:""
显示在选择器顶部的文本。
time
struct Time 默认:a struct with all default values
设置初始显示的时间。
slint
TimePickerPopup { time: { hour: 12, minute: 24 };}Time
使用小时、分钟和秒定义时间。
hour(int):小时值(范围 0 到 23)。minute(int):分钟值(范围 1 到 59)。second(int):秒值(范围 1 到 59)。
回调
canceled()
点击了取消按钮。
slint
time-picker := TimePickerPopup { canceled() => { time-picker.close(); }}accepted(Time)
点击了确定按钮。
slint
time-picker := TimePickerPopup { accepted(time) => { debug("Selected time: ", time); time-picker.close(); }}