是否可以遍历 ListView
的代表?或 GridView
使用 foreach
或类似的功能?
最佳答案
虽然 Simon 的回答是最佳实践,但要回答所提出的实际问题,您需要遍历 children
的 ListView
的contentItem
像这样:
ListView {
id: list
model: mymodel
delegate: Text {
objectName: "text"
text: name + ": " + number
}
}
for(var child in list.contentItem.children) {
console.log(list.contentItem.children[child].objectName)
}
然后,您可以使用 objectName 或委托(delegate) Item 的任何其他属性进行过滤。
关于qt - QML View 中的 Foreach 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29329575/