如何使用qml DelegateModelGtoup解析函数

时间:2017-10-20 08:43:27

标签: qt qml

我是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)
                        }
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案