Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] item reinizialized when scrolling GridView
QtWS25 Last Chance

[solved] item reinizialized when scrolling GridView

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deimos
    wrote on last edited by
    #1

    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:
    @
    ThumbGrid.qml
    GridView {
    id: gridViewThumb
    objectName: "gridViewThumb"
    model: listModel
    delegate: Thumb {}
    }@

    Thumb.qml
    @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
    {
    Q_OBJECT
    public:
    enum ThumbRoles {
    propertiesRole = Qt::UserRole + 1,
    IDRole,
    description_row1Role,
    ...
    };

    ThumbModelList(QObject *parent = 0);
    ~ThumbModelList();
    
    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;
    

    private:
    QList<ThumbItem*> m_thumbs;

    };@

    and ThumbItems is like this
    @class ThumbItem : public QDeclarativeItem
    {
    Q_OBJECT

    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)
    ...
    

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

    int m_ID;
    QString m_description_row1;
    ...
    

    signals:
    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deimos
      wrote on last edited by
      #2

      I solved the issue Reading [TF] manual :)
      using "cacheBuffer":http://doc.qt.nokia.com/4.7-snapshot/qml-gridview.html#cacheBuffer-prop 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++

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved