QML listview Transition不适用于C ++ Model

时间:2016-05-27 13:08:46

标签: qml qlistview

我试过这个例子来添加动画。它有效。

 ListView {
    width: 240; height: 320
    model: ListModel {}

    delegate: Rectangle {
        width: 100; height: 30
        border.width: 1
        color: "lightsteelblue"
        Text {
            anchors.centerIn: parent
            text: name
        }
    }

    add: Transition {
        NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 }
        NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 }
    }

    displaced: Transition {
        NumberAnimation { properties: "x,y"; duration: 400; easing.type: Easing.OutBounce }
    }

    focus: true
    Keys.onSpacePressed: model.insert(0, { "name": "Item " + model.count })
} 

当在模型中插入新记录时,依次添加动画作品。但我想将模型引用到C ++列表中:

model:mymodel.list 

当我将新记录添加到列表时,listmodel已更新但添加动画未生效

我使用QAbstractItemModel找到解决方案

0 个答案:

没有答案