5
我需要一些帮助,添加元素为QML列表视图,我有一个textarea和一个按钮,将增加textarea的文本被按下时,ListView项,这里是我的尝试:QML,动态地添加元素到ListView
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 = ""
}
}
我试图追加它,但没有显示在列表视图中......任何帮助?
在p1button onClicked,您清除在文本区文本* *前添加文本到ListModel的,当然文字也不会显示向上。 – Dickson
该文本仍然不显示,我认为它与代表的问题...(编辑问题) – Hairo
我不知道,但...更改您的委托组件id到别的东西,因为当你在你的ListView中使用'delegate:delegate',它假设是'delegate:p1scores.delegate',所以它绑定回自己。 – Dickson