Skip to content
slint
import { Switch } from "std-widgets.slint";export component Example inherits Window {    width: 200px;    height: 40px;
    Switch {        text: "Hello World";    }}

std-widgets switch example

Switch 表示一个物理开关,允许用户打开或关闭某些东西。如果你希望用户从多个选项中选择或取消选择值(例如在具有多个选项的列表中),请考虑改用 CheckBox

属性

checked

bool (in-out) 默认:false

开关是否被勾选。

slint
Switch {    text: self.checked ? "Checked" : "Not checked";    checked: true;}

enabled

bool 默认:false

当为 false 时,无法按下开关。

has-focus

bool (out) 默认:false

当开关具有键盘焦点时设置为 true。

text

string 默认:""

显示在开关旁边的文本。

slint
Switch {    text: "Switch with text";}

回调

toggled()

开关值发生更改时调用。

slint
Switch {    text: "Switch";    toggled() => {        debug("CheckBox checked: ", self.checked);    }}

基于 MIT 协议发布