Important: Please read the Qt Code of Conduct -

selection update on model sorting/re-ordering with Qt

  • I'm trying do redefine a proxy model that can do sorting and re-ordering (the user can order each row as he wants).

    As far as I'm aware, there's nothing straight out of the box in Qt to do that, so I'm desperately trying to make my own proxy model, inheriting QAbstractProxyModel.

    I based most of what I did on the actual code of QSortFilterProxyModel, but I'm still missing some features.

    Most important to me is the selection after sorting/reordering.

    If I use a QSortFilterProxyModel, the selection on my table view follows the sort (ie, the same item is selected), but if I use my model, it does not (the same line stays selected).

    Anyone has any idea how this behavior is done with QSortFilterModel? does it have anything to do with these weird persistent indexes I don't really understand?

  • Moderators

    why dont you use QSortFilterProxyModel directly?

    Inherit QSortFilterProxyModel, and reimplement lessThan() method. And do the comparison based on your own sort order.

  • Yeah but the user also want to be able to reorder things as he wants, not just sort (ie, put this row here, drag all my selection at this position, invert these two rows, ...)