Reorder Row items in ListView with SortFilterProxyModel
-
I want to create a movement of items in a ListView as you can see at:
https://doc.qt.io/qt-5/qml-qtquick-viewtransition.html under Restrictions Regarding ScriptActionI have:
ListView { ... model: SortFilterProxyModel populate: Transition { NumberAnimation { properties: "y" duration: 1000 } } ... delegate: Row { ... Text { text: SortFilterProxyModel.name } Text { text: SortFilterProxyModel.prename } }I can't use SortFilterProxyModel.move() because this method does not exist. My SortFilterProxyModel is sorted by the method SortProxyModel::sort() in my C++-Code.
How can I animate the reorder of the row items in my view? The populate - transistion moves all rows from the top of the ListView to each position of the item. But I want the simulation of the above url. For example: second row of ListView moves to row 8 and the rows 1, 3-7 moves one row upwards and the rows 8-10 moves one row downwards.
How can I get this? -
I guess your
SortFilterProxyModelis a subclass ofQSortFilterProxyModel, this class doesn't really behave well regarding rows being moved around.If the source model move its row, it will emit a layoutChanged signal. Same thing if the rows need to be moved due to their data being changed and the sorting thus being affected.
This means that the
moveormoveDisplacedtransitions in a ListView using a QSortFilterProxyModel will never be called.
An alternative could be using SortProxyModel from KDtoolBox by KDAB