Switch
import { Switch } from "std-widgets.slint";export component Example inherits Window { width: 200px; height: 40px;
Switch { text: "Hello World"; }
}slint
Switch 是物理开关的表示形式,允许用户打开或关闭某物。如果希望用户选择或取消选择值(例如在具有多个选项的列表中),请考虑改用 CheckBox。
checked
Section titled “checked”bool(in-out)default: false
开关是否已选中。
Switch { text: self.checked ? "Checked" : "Not checked"; checked: true;}slint
enabled
Section titled “enabled”booldefault: true
当为 false 时,开关无法被按下
has-focus
Section titled “has-focus”bool(out)
当开关具有键盘焦点时设置为 true
toggled()
Section titled “toggled()”开关的值发生了变化
Switch { text: "Switch"; toggled() => { debug("Switch checked: ", self.checked); }}slint
© 2026 SixtyFPS GmbH