Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore original order in QTableView/QSortFilterProxy

Tags:

c++

qt

I have a QTableView with QSortFilterProxyModel between the view and the model (QStandardItemModel). The problem is when I call sort() I'm unable to restore original order of lines in a table. I was trying to acheve that by changing model proxy to QIdentityProxy on-the-fly but to no avail, as the only change is that lines are renumbered but order is kept sorted.

Is it possible to somehow "unsort" data? I think, that code is unnecessary in this case, but will post if asked.

I'm using Qt5 on Win x64

P.S.: The same problem was posted here back in 2009 but never was answered.

like image 473
sukhmel Avatar asked Sep 05 '13 13:09

sukhmel


Video Answer


1 Answers

To restore initial unsorted state ( tested )

    sortModel->setSortRole(Qt::InitialSortOrderRole);
    sortModel->invalidate();

QSortFilterProxyModel::​setSortRole(int role)

like image 118
fbucek Avatar answered Sep 22 '22 10:09

fbucek