Мне нужна помощь с добавлением элементов в список qml, у меня есть текстовое поле и кнопка, которая добавит текст текстового поля в элемент списка при нажатии, вот моя попытка:
Component {
id: delegate
Item {
width: 200; height: 28
Label {
text: score
}
}
}
ListView {
id: p1scores
model: p1model
delegate: delegate
anchors.top: p1name.bottom
anchors.topMargin: units.gu(1)
}
ListModel {
id: p1model
ListElement { score: "0" }
}
TextArea {
id: p1input
width: units.gu(8)
height: units.gu(3)
horizontalAlignment: TextEdit.AlignHCenter
inputMethodHints: Qt.ImhDigitsOnly
contentHeight: units.gu(60)
anchors.topMargin: units.gu(8)
}
Button {
id:p1button
text: i18n.tr("Add")
width: units.gu(8)
onClicked: {
p1model.append({"score": p1input.text})
p1input.text = ""
}
}
я попытался добавить его, но он не отображается в списке ... любая помощь?
delegate
на что-то другое, потому что, когда вы используетеdelegate: delegate
в своем ListView, предполагается, что этоdelegate: p1scores.delegate
, поэтому он привязывается к себе. - person Dickson   schedule 23.01.2013