我是qt / qml的新手,我想动态地使用DelegateModel
添加元素。但我发现元素的isUnresolved
属性始终为true。
import QtQuick 2.0
import QtQml.Models 2.2
Rectangle {
width:1280
height:720
ListModel{
id:delegateModel
ListElement{
name:'USA'
}
ListElement{
name:'JP'
}
ListElement{
name:'UK'
}
ListElement{
name:'ZH'
}
ListElement{
name:'GEO'
}
}
ListView{
id:view
anchors.fill: parent
snapMode: ListView.SnapOneItem
orientation: ListView.Horizontal
boundsBehavior: Flickable.StopAtBounds
displaced: Transition {
id:displacedTransition
NumberAnimation {
properties: "x,y";easing.type: Easing.OutQuad
}
}
remove: Transition {
id:removeTransition
NumberAnimation {
properties: "x,y";easing.type: Easing.OutQuad
}
}
model:DelegateModel{
id:visualModel
model:delegateModel
delegate:Item{
width:256
height:720
Rectangle{
anchors.centerIn: parent
width:256*0.8
height:width
radius:width/2
color:Qt.rgba(1,0.4,0.4,0.6)
Text{
anchors.centerIn:parent
text:name
}
MouseArea{
anchors.fill: parent
onClicked: {
visualModel.items.insert(index,{name:"prev"+name})
console.log(visualModel.items.get(index).isUnresolved)
visualModel.items.resolve(index,index)
console.log(visualModel.items.get(index).isUnresolved)
}
}
}
}
}
}
}