문제

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