ExclusiveGroup as 属性 将不起作用
ExclusiveGroup as property won't work
我有一个自定义 Footer
Component
,它有一个 RowLayout
,可以按照 方法向其中添加子项 (Button
s)。
现在我希望 Button
可以检查,但一次只能检查一个 Button
。所以我定义了一个 ExclusiveGroup
添加了 internal Footer
Button
s。 这有效。一次只能检查其中 Button
个。
为了将 外部 按钮添加到相同的 ExclusiveGroup
,我添加了一个 属性 来显示它。但这 不 起作用。我收到此错误:
qrc:/main.qml:13:20: Unable to assign [undefined] to QQuickExclusiveGroup*
qrc:/main.qml:19:20: Unable to assign [undefined] to QQuickExclusiveGroup*
这是代码:
main.qml
Window {
visible: true
Footer {
Button {
text: "extern 1"
checkable: true
exclusiveGroup: parent.radioInputGroup
}
Button {
text: "extern 2"
checkable: true
exclusiveGroup: parent.exclusiveGroup
}
}
}
Footer.qml
Rectangle {
color: "gold"
height: 50
default property alias content: rowLayout.children
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
RowLayout {
id: rowLayout
anchors.fill: parent
anchors.margins: 10
property var exclusiveGroup: radioInputGroup
ExclusiveGroup {
id: radioInputGroup
}
Button {
id: button
text: "intern 1"
checkable: true
exclusiveGroup: radioInputGroup
}
Button {
text: "intern 2"
checkable: true
exclusiveGroup: radioInputGroup
}
}
}
我怎样才能让它工作?
除了带有文本 extern 1
的 Button
之外,似乎对我有用。您必须将 exclusiveGroup
从 parent.radioInputGroup
更改为 parent.exclusiveGroup
。
我有一个自定义 Footer
Component
,它有一个 RowLayout
,可以按照 Button
s)。
现在我希望 Button
可以检查,但一次只能检查一个 Button
。所以我定义了一个 ExclusiveGroup
添加了 internal Footer
Button
s。 这有效。一次只能检查其中 Button
个。
为了将 外部 按钮添加到相同的 ExclusiveGroup
,我添加了一个 属性 来显示它。但这 不 起作用。我收到此错误:
qrc:/main.qml:13:20: Unable to assign [undefined] to QQuickExclusiveGroup*
qrc:/main.qml:19:20: Unable to assign [undefined] to QQuickExclusiveGroup*
这是代码:
main.qml
Window {
visible: true
Footer {
Button {
text: "extern 1"
checkable: true
exclusiveGroup: parent.radioInputGroup
}
Button {
text: "extern 2"
checkable: true
exclusiveGroup: parent.exclusiveGroup
}
}
}
Footer.qml
Rectangle {
color: "gold"
height: 50
default property alias content: rowLayout.children
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
RowLayout {
id: rowLayout
anchors.fill: parent
anchors.margins: 10
property var exclusiveGroup: radioInputGroup
ExclusiveGroup {
id: radioInputGroup
}
Button {
id: button
text: "intern 1"
checkable: true
exclusiveGroup: radioInputGroup
}
Button {
text: "intern 2"
checkable: true
exclusiveGroup: radioInputGroup
}
}
}
我怎样才能让它工作?
除了带有文本 extern 1
的 Button
之外,似乎对我有用。您必须将 exclusiveGroup
从 parent.radioInputGroup
更改为 parent.exclusiveGroup
。