PDA

View Full Version : Problem with updating QTreeView with QAbstractITemModel



Mohsin
28th April 2021, 05:24
Currently, there is a problem with line number 5, QT doesn't allow to change the QTreeWidget model.

Is there a view to fixing this problem? instead of using QtreeView.



QAbstractItemModel * sourceModel;
sourceModel = ui->treeWidget->model();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(sourceModel);
ui->treeWidget->QTreeWidget::setModel(proxyModel);

ChristianEhrlicher
28th April 2021, 10:22
You must not change the model of a QTree/Table/ListWidget - if you want to set a custom model, use the corresponding QTree/Table/ListView classes.
You don't need a QSortFilterProxyModel for a QTreeWidget. See the documentation how to achieve sorting there: https://doc.qt.io/qt-5/qtreewidgetitem.html#operator-lt