我尝试突出显示 unchecked RadioButton
,同时悬停选中。悬停时不应突出显示选中的 RadioButton 或以其他方式突出显示。
为此,我使用功能borderColor(hovered)
。
我得到错误TypeError: Cannot read property 'border' of undefined
。
是否可以将children[i].style
(type Component
) 转换为RadioButtonStyle
?
Column {
x: 223
y: 100
width: 104
height: 45
anchors.verticalCenterOffset: 2
anchors.verticalCenter: parent.verticalCenter
spacing: 5
LayoutMirroring.enabled: true
LayoutMirroring.childrenInherit: true
function borderColor(hovered) {
for (var i = 0; i < children.length; ++i) {
var notChecked = !children[i].checked;
if(notChecked) {
children[i].style.indicator.border.color = hovered ? "blue" : "gray";
}
}
}
ExclusiveGroup { id: exGr }
RadioButton {
checked: true
text: "one"
exclusiveGroup: exGr
style: RadioButtonStyle {
label: Label {
text: control.text
font.pointSize: 14
anchors.margins: 0
}
indicator: Rectangle {
implicitWidth: 16
implicitHeight: 16
border.color: "gray"
border.width: 1
Rectangle {
anchors.fill: parent
visible: control.checked
color: "#555"
anchors.margins: 4
}
}
}
onHoveredChanged: {
if(checked) {
parent.borderColor(hovered);
}
}
}
RadioButton {
text: "two"
exclusiveGroup: exGr
style: RadioButtonStyle {
label: Label {
text: control.text
font.pointSize: 14
anchors.margins: 0
}
indicator: Rectangle {
implicitWidth: 16
implicitHeight: 16
border.color: "gray"
border.width: 1
Rectangle {
anchors.fill: parent
visible: control.checked
color: "#555"
anchors.margins: 4
}
}
}
onHoveredChanged: {
if(checked) {
parent.borderColor(hovered);
}
}
}
RadioButton {
text: "three"
exclusiveGroup: exGr
style: RadioButtonStyle {
label: Label {
text: control.text
font.pointSize: 14
anchors.margins: 0
}
indicator: Rectangle {
implicitWidth: 16
implicitHeight: 16
border.color: "gray"
border.width: 1
Rectangle {
anchors.fill: parent
visible: control.checked
color: "#555"
anchors.margins: 4
}
}
}
onHoveredChanged: {
if(checked) {
parent.borderColor(hovered);
}
}
}
}