Answer the question
In order to leave comments, you need to log in
Qt: How to use QSortFilterProxyModel in conjunction with a view?
I have a project that until recently used a RecordTableModel extended from the QAbstractTableModel class . In this model, in addition to the overridden standard methods, additional methods were added that simplified the interaction between the view and the model:
void RecordTableModel::setTableData(RecordTableData *rtData)
RecordTableData *RecordTableModel::getTableData(void)
int RecordTableModel::addTableData(int mode,
int pos,
QMap<QString, QString> fields,
QString text,
QMap<QString, QByteArray> files)
void RecordTableModel::removeRowsByList(QVector<int> delIdx)
// Было
recordModel=new RecordTableModel();
setModel(recordModel);
...
// Стало
recordSourceModel=new RecordTableModel();
recordModel=new QSortFilterProxyModel();
recordModel->setSourceModel(recordSourceModel);
setModel(recordModel);
Answer the question
In order to leave comments, you need to log in
And you do not need to manage data through a proxy model. Do it directly with RecordTableModel and QSortFilterProxyModel will only sort.
Understand that the data should be stored only in the model (i.e. in the RecordTableModel) and it is she who should work with them, and no one else. QSortFilterProxyModel in this case will only change the display format of this data, but not the data itself.
I recommend to pull up knowledge about models. You can do this, for example, here .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question