
Originally Posted by
Jennie Bystrom
I have two table views that should visualize the same data. One is a filtered version of the other so it will not show all columns. I call them collapsedView and expandedView. Both are QTableView.
You don't need a proxy model to hide columns if that's all difference between them. You can use QTableView::setColumnHidden().
SourceModel* sourceModel = new SourceModel();
FilterModel* filterModel = new FilterModel();
filterModel->setSourceModel(sourceModel);
collapsedView->setModel(filterModel);
expandedView->setModel(filterModel);
collapsedView->setColumnHidden(2, true); // hide for example second column
QTableView* collapsedView = new QTableView();
QTableView* expandedView = new QTableView();
SourceModel* sourceModel = new SourceModel();
FilterModel* filterModel = new FilterModel();
filterModel->setSourceModel(sourceModel);
collapsedView->setModel(filterModel);
expandedView->setModel(filterModel);
collapsedView->setColumnHidden(2, true); // hide for example second column
To copy to clipboard, switch view to plain text mode
This way sorting should work correctly out of the box in both views.
Bookmarks