Solved How get delegates to move along when sorting a QTableView
-
I have a setup where the delegate widget type, i.e. the one returned by createEditor in the delegate class, for column x in a QTableView depends on which row it is. I've implemented sorting in my model according to the pattering in https://doc.qt.io/qt-5/qabstractitemmodel.html#layoutChanged and also glanced on the QTableWidget source. It works fine for the values but the delegates doesn't move along, they're left in their old position. Hence I think that my calls to update persistent index,
for (int i = 0; i < rowCount(); i++) { for (int c = 0; c < columnCount(); c++) { changePersistentIndex(createIndex(sortResult[i], c), createIndex(i, c)); } }
is correct. Anyone who knows what's required for the delegates to update their position? QStyledItemDelegate::updateEditorGeometry is called but option.rect is the same regardless of sorting. Not using QSortFilterProxyModel since the underying data should change at sorting.
-
Use a QSortFilterProxyModel instead.
-
Solved. For some reason one had to put the index updates in lists and use changePersistentIndexList().