Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 ScriptAction

    I 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?


  • Qt Champions 2018

    I guess your SortFilterProxyModel is a subclass of QSortFilterProxyModel, 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 move or moveDisplaced transitions in a ListView using a QSortFilterProxyModel will never be called.
    An alternative could be using SortProxyModel from KDtoolBox by KDAB


Log in to reply