【问题标题】:Add an element to a repeater with animation将元素添加到带有动画的转发器
【发布时间】:2013-08-08 07:36:33
【问题描述】:

我有一个中继器,它的元素在创建时是动画的。

Repeater {
    model : 0

    Image {
       ...

       Animation {
           ...
       }
    }
}

如果我在前一个元素的动画完成后向模型添加一个元素,一切正常。但是如果我之前添加一个元素,它就不起作用了。 例如,如果我有一把能射出子弹的枪,如果我等到子弹动画结束,一切正常。但是如果我想在第一个结束之前再射一颗子弹,第一个会消失,我只会看到第二个的动画。

我应该怎么做才能看到所有的动画?

【问题讨论】:

    标签: javascript qt qml qt-quick qtquick2


    【解决方案1】:

    也许您的模型或委托,或布局(项目重叠...)有问题,因为在这里,这工作正常:

    import QtQuick 2.0;
    
    Rectangle {
        width: 400;
        height: 300;
    
        Timer {
            running: true;
            repeat: true;
            interval: 1000;
            onTriggered: { modelTest.append ({ "bg" : Qt.hsla (Math.random (), 0.85, 0.45, 1.0).toString () }); }
        }
        Flow {
            anchors.fill: parent;
    
            Repeater {
                model: ListModel {
                    id: modelTest;
                }
                delegate: Rectangle {
                    id: rect;
                    color: model.bg;
                    width: 50;
                    height: width;
                    scale: 0.0;
    
                    PropertyAnimation {
                        target: rect;
                        property: "scale";
                        from: 0.0;
                        to: 1.0;
                        duration: 450;
                        running: true;
                        loops: 1;
                    }
                }
            }
        }
    }
    

    请记住,只有 ListModel 和 QAbstractListModel 能够在不重置整个委托的情况下动态添加新项目,另一个(变体列表、JS 数组、数字)将导致在每次模型修改时重新实例化所有委托...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 2022-08-23
      • 2018-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多