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

Mark markg85 at gmail.com
Wed Aug 14 16:23:03 CEST 2013


On Wed, Aug 14, 2013 at 10:34 AM, Ola Røer Thorsen <ola at silentwings.no> wrote:
> I'd like to animate the sorting of a live scoreboard, using Quick2 and
> c++. It's for covering a live sports racing event, but the same would
> apply if you imagine you have to create the score board for the voting
> segment of the Eurovision Song Contest or something.
>
> My data model is based on QAbstractListModel, and I sort it using the
> QSortFilterProxyModel. Finally it's displayed in a Quick2 ListView.
>
> I think I might have hit a severe limitation in ListView or something,
> it does not seem to grasp the re-ordering of elements in the list, it
> just thinks the contents of each entry changed instead. So the item on
> the top of the list always has index 0, etc. This prevents animation of
> re-ordering, only animation of adding/removing elements on the end of
> the list is possible.
>
> Same issue occurs when filtering a list, it's not the items filtered out
> that really disappear from the list, it's just the ones that happen to
> be on the bottom.
>
> Anyone know how to animate the sorting of a ListView? (hopefully without
> Javascript hacks...)
>
> Thanks!

That is a very interesting question! One that i would probably ask
sometime soon as well so i dived in the (severely broken [1]) QML
documentation. I found only one way of doing what you request but that
will require quite a bit of bookkeeping work on your part. The part i
found is [2] but even with that it seems like you have to do very deep
QML source digging because i can't find any function reference for
<model>.move(int, int, int). I either can't find it in the logical
places (ListModel, QAbstractItemModel, QAbstractListModel) so it's
either not documented or very well hidden.

The bookkeeping i referred to earlier is the index stuff. You can't
"just" use QSortFilerProxyModel with the above stuff. You somehow need
to do the sorting, remember the old indexes and where they moved to
and pass that on to QML. It seems like a lot of work and very error
prone so i can't imagine that there isn't a better way to do this...

If there  is a better way - or if you find a better way - please do
mention that on this thread :)

[1] broken as in a lot of links simply don't work. Really bad.
[2] http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-viewtransition.html#restrictions-regarding-scriptaction



More information about the Interest mailing list