QML로 테스트 시스템을 구현하고 있습니다. 섹션 (예 : 질문)에서 일부 대답을 누른 후 answered
은 true
에서 변경되어야하므로 더 이상이 섹션에서 답을 누를 수 없습니다. 나는 answerDelegate
MouseArea
클릭 핸들러에서 확인합니다. 하지만 answered
속성에 액세스 할 수 없습니다.다른 구성 요소의 구성 요소 속성 가져 오기
어떻게 연결하나요?
Rectangle {
id: root
anchors.fill: parent
property ListModel testModel: ListModel {}
property int totalAnswers: 0
property int questionsCount: 0
function setTestModel(tests){
testModel.clear()
testModel.append(tests)
}
ScrollView {
id: testsScroll
anchors.fill: parent
ListView {
id: testsView
anchors.fill: parent
model: testModel
delegate: answersDelegate
section.property: "question"
section.delegate: questionDelegate
}
}
Component {
id: questionDelegate
Rectangle{
id: questionItem
// the property I need to get access
property bool answered: false
width: parent.width
height: 40
Text {
anchors.left: parent.left
text: section
}
Component.onCompleted: {
questionsCount += 1
}
}
}
Component {
id: answersDelegate
Item {
id: oneItem
width: parent.width
height: 30
Rectangle {
id: answerRectangle
Text {
anchors.left: parent.left
text: content
}
MouseArea {
anchors.fill: parent
onClicked: {
// here I check it
root.answerClicked()
if (!questionDelegate.answered) {
questionDelegate.answered = true
answerRectangle.color = correct == true ? "#00ff00": "#ff0000"
if (correct) total += 1
}
}
}
}
}
}
}