ExclusiveGroup
ImportStatement: import QtQuick.Controls 1.2
Properties
current :object
Methods
voidbindCheckable(object)
voidunbindCheckable(object)
DetailedDescription
ExclusiveGroup能包含多个Action组件。组件自动获得Action::exclusiveGroup属性分配。
例如:
ExclusiveGroup{
id: radioInputGroup
Action {
id: dabRadioInput
text: "DAB"
checkable: true
}
Action {
id: fmRadioInput
text: "FM"
checkable: true
}
Action {
id: amRadioInput
text: "AM"
checkable: true
}
}
多个组件已经支持ExclusiveGroup,例如Action、MenuItem、Button和RadioButton。
如果ExclusiveGroup仅仅作为子组件被支持,我们需哟手动的分配对象的独立组属性。
例如:
ExclusiveGroup{ id: textAlignmentGroup }
Menu {
MenuItem {
text: "Alignt Left"
checkable: true
exclusiveGroup: textAlignmentGroup
}
MenuItem {
text: "Alignt Right"
checkable: true
exclusiveGroup: textAlignmentGroup
}
MenuItem {
text: "Center"
checkable: true
exclusiveGroup: textAlignmentGroup
}
MenuItem {
text: "Justify"
checkable: true
exclusiveGroup: textAlignmentGroup
}
}
Addingsupport to ExclusiveGroup
为一个控件或对象增加ExclusiveGroup支持是可能的。我们需要有checked属性和checkedChanged、toggled()、toggled(bool)中的一个信号。当ExclusiveGroup属性被设置时,我们还需要绑定ExclusiveGroup::bindCheckable()。
Item {
id: myItem
property bool checked: false
property ExclusiveGroup exclusiveGroup: null
onExclusiveGroupChanged: {
if (exclusiveGroup)
exclusiveGroup.bindCheckable(myItem)
}
}
例子是为任意item添加ExclusiveGroup的最少代码。
PropertyDocumentation
current :object
当前选择的对象。默认为绑定到独立组的第一个对象。如果没有,则默认为空。
MethodDocumentation
void bindCheckable(object)
注册一个对象到独立组。当我们想让创建的组件与独立组兼容,只需要调用这个方法。同时参阅ExclusiveGroup::unbindCheckable()。
voidunbindCheckable(object)
从独立组解除对象的注册。当我们需要从独立组中移除我们注册的创建组件,调用这个函数。