[Interest] Quick2 - animate sorting of listview, sorted with QSortFilerProxyModel

Nils Jeisecke njeisecke at saltation.de
Wed Aug 14 17:30:38 CEST 2013


On Wed, Aug 14, 2013 at 4:59 PM, Mark <markg85 at gmail.com> wrote:
> But does resorting the model call those functions internally? Or does it
> simply notify that "the model changed" which would cause the entire view to
> be updated...

AFAIK QSortFilterProxyModel does not emit the rowsMoved signal, only
rowsRemoved/rowsInserted. So this won't be properly animated.

You must implement the sorting directly in your model and then use
beginMoveRows/endMoveRows. This shouldn't be so difficult for a score
model.

Here's some code:

---

class ScoreModel
{
// ...
  QList<ScoreEntry> m_entries;
// ...
};

void ScoreModel::move(int from, int to)
{
  if (to == from)
    return;

  // beginMoveRows "to" means => before "to"
  int modelTo = to;
  if (to > from)
    modelTo++;

  // register move for views
  if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), modelTo)) {
    qFatal() << "MOVING FAILED";
    return;
  }

  // actually move item in container
  m_entries.move(from, to);

  // now the qml view should animate a move
  endMoveRows();
}

---

Nils



More information about the Interest mailing list