Important: Please read the Qt Code of Conduct -

[solved] item reinizialized when scrolling GridView

  • Hi,
    I have a QAbstractListModel as a delegate for a GridView. I would like to make an animation when a new item is added and this work, but when I scroll the view, the items that come visible are like reloaded and the animation will occurs again. I tried different ways, but I didn't get it to work. How could I procede ?
    Here some code:
    GridView {
    id: gridViewThumb
    objectName: "gridViewThumb"
    model: listModel
    delegate: Thumb {}

    @Rectangle {
    id: thumbRect
    objectName: "item"+ID

    scale: 1
    NumberAnimation on scale {
          from: 0.1; to: 1.0
          duration: 1000
          easing.type: Easing.OutBounce


    The listModel is a QAbstractListModel subclass
    @class ThumbModelList : public QAbstractListModel
    enum ThumbRoles {
    propertiesRole = Qt::UserRole + 1,

    ThumbModelList(QObject *parent = 0);
    void addThumb(const ThumbStruct &thumb);
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;

    QList<ThumbItem*> m_thumbs;


    and ThumbItems is like this
    @class ThumbItem : public QDeclarativeItem

    Q_PROPERTY(ThumbStruct properties READ properties WRITE setProperties NOTIFY propertiesChanged)
    Q_PROPERTY(int     ID               READ ID               WRITE setID               NOTIFY IDChanged)
    Q_PROPERTY(QString description_row1 READ description_row1 WRITE setDescription_row1 NOTIFY description_row1Changed)

    ThumbItem(QDeclarativeItem *parent=0);
    ThumbItem(const ThumbStruct &properties, QDeclarativeItem *parent=0);

    int m_ID;
    QString m_description_row1;

    void propertiesChanged();
    void IDChanged();
    void description_row1Changed();

    I tried to add a boolean animation Q_PROPERTY, but within Thumb.qml I can't see onAnimationChanged signal.
    I tried also to put

    @PropertyAnimation { id:bounce; objectName: "bounce"; target: thumbRect; properties: "scale"; from: 0.1; to: 1; easing.type: Easing.OutBounce }@

    inside Thumb.qml, but how to set "bounce.running=true" from c++ ?
    Thanks for your time

  • I solved the issue Reading [TF] manual :)
    using "cacheBuffer": property of GridView
    "This property determines whether delegates are retained outside the visible area of the view"

    but I cannot still handle how to start the animation from c++

Log in to reply