我在章节顶部有一些项目。窗户。其中的任务是选择操作模式,然后窗口关闭并显示章节。窗户。我还没有绑定 C++ 类,所以大多数类似的问题都没有帮助。发生错误:在第二种情况下无法将 [undefined] 分配给 bool。
发生:
1-在正确的项目中创建两个自定义单选按钮-> 全部确定;
2- 从单独的文件中调用所需项目中的两个自定义单选按钮->可见错误:parent.checked。
DarkRadioButton.qml
import QtQuick 2.14
import QtQuick.Controls 2.14
RadioButton {
checked: false
indicator: Rectangle {
implicitWidth: 20
implicitHeight: 20
x: payloadRole.horizontalPadding
y: payloadRole.height / 2 - height / 2
radius: 0
border.color: Qt.rgba( 255/255., 0/255., 0/255., 1)
color: Qt.rgba( 32/255., 32/255., 32/255., 1)
Rectangle {
id: radioButtonBox
width: 16
height: 16
x: 2
y: 2
Image {
anchors.fill: radioButtonBox
source: "qrc:/res/resources/DarkRadioButtonBox.png"
fillMode: Image.PreserveAspectCrop
sourceSize.width: 200
sourceSize.height: 200
}
visible: parent.checked //!!!!!!!!!! ошибка !!!!!!!!!!!!
}
}
contentItem: Text {
text: parent.text
font: parent.font
color: Qt.rgba( 255/255., 255/255., 255/255., 1)
verticalAlignment: Text.AlignVCenter
leftPadding: parent.indicator.width + parent.spacing
}
onCheckedChanged: {
//some extern value function (not here yet)
optionsWindow.visible = false
}
}
通话地点:有条件的main.qml
//---
Item {
//---
ColumnLayout{
width: dialog.width
height: dialog.height
DarkRadioButton {
id: optionA
text: qsTr("Option 1")
Layout.alignment: Qt.AlignCenter
}
DarkRadioButton {
id: optionB
text: qsTr("Option 2")
Layout.alignment: Qt.AlignCenter
}
关闭项目有效,但我计划继续使用此模板。我不知道这个错误是否会干扰,所以我决定寻求帮助。
您的父对象是一个没有选中属性的 Rectangle。
修正版