slint
import { CheckBox } from "std-widgets.slint";export component Example inherits Window { width: 200px; height: 25px; background: transparent; CheckBox { x: 5px; width: parent.width; height: parent.height; text: "Hello World"; }}
使用 CheckBox 让用户选择或取消选择值,例如在具有多个选项的列表中。如果该操作更像是打开或关闭某个东西,请考虑使用 Switch 元素。
属性
checked
bool (in-out) 默认:false
复选框是否被勾选。
slint
CheckBox { text: self.checked ? "Checked" : "Not checked"; checked: true;}enabled
bool 默认:true
默认为 true。当为 false 时,无法按下复选框。
has-focus
bool (out) 默认:false
当复选框具有键盘焦点时设置为 true。
text
string 默认:""
显示在复选框旁边的文本。
slint
CheckBox { text: "CheckBox with text";}回调
toggled()
复选框的值发生更改时调用。
slint
CheckBox { text: "CheckBox"; toggled() => { debug("CheckBox checked: ", self.checked); }}