سؤال

let's say i have the following QML Components:

Foo.qml

import Qt 4.7

Rectangle {
  Repeater {
    model: myModel
    delegate: Bar {
      barProp: elemProp
    }
  }
}

Bar.qml

import Qt 4.7

Rectangle {
  property string barProp: ""

  Text {
    text: barProp

    NumberAnimation on x {
      from: 0; to: 100
      duration: 1000
      loops: Animation.Infinite
    }
  }
}

I maintain myModel from C++, it has the following Q_PROPERTY declaration:

Q_PROPERTY (QDeclarativeListProperty <Bar> myModel READ myModel
            NOTIFY myModelChanged)

Now, my problem is that every time I add a new element to the underlying QList, the animation specified in Bar resets, so in practice, the elements always completely overlap. What I want is that the element animations are not synchronous, and each can continue seamlessly regardless of the rest. Is this possible to do?

Cheers

هل كانت مفيدة؟

المحلول

You should use a QAbstractItemModel (QStandardItemModel may be easiest) rather than a QList. QAbstractItemModel notifies the view when new items are inserted/removed/moved and the view reacts appropriately by modifying its content. In contrast, the view knows nothing about the changes made to a QList; only that something has changed. This means that the list has no choice but to destroy and recreate all delegates.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top