PDA

View Full Version : QSortFilterProxyModel not updating



karn862
31st October 2010, 15:27
Hello,

I'm using a QSortFilterProxyModel in order to keep the rows of a tableview sorted by the values in the column 'index'.
When i change a value in the column 'index', the tableview is updated accordingly but the proxy model doesn't re-apply the sorting automatically.
However when i sort the column 'index' manually by clicking on its header once, then the proxy model updates itself for every future modification of values in the column, as i would like it to do.
So my question is : what happens when i click on the header of the column that i don't do programatically ?

Here is my code :


MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);

this->proxyModel = new QSortFilterProxyModel();

proxyModel->setSourceModel(model);
proxyModel->setDynamicSortFilter(true);
proxyModel->sort(0, Qt::AscendingOrder);

ui->tableView->setModel(proxyModel);
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
}

Thank you.

ChrisW67
31st October 2010, 23:16
Look at QSortFilterProxyModel::setDynamicSortFilter()