user2836797
user2836797

Reputation:

Sharing one model between two views that display different columns of data

In this case, I am working with legacy code. I have a large dequeue data structure. This is the data source. I need two QTableView widgets on a single dialog that utilize the same data source but show different columns of data. Since each table displays different columns of data, how can they share the same QAbstractItemModel? Is this what proxy models are for?

Upvotes: 3

Views: 2079

Answers (1)

Nejat
Nejat

Reputation: 32635

Proxy models (QSortFilterProxyModel or QAbstractProxyModel) are for filtering, sorting or other data processing tasks. In your case you should use the same model for two different views and just hide the unnecessary columns in each view :

QTableView *tableView = new QTableView();
QTableView *secondtableView = new QTableView();

MyModel *model = new MyModel();

tableView->setModel(model);
secondtableView->setModel(model);

tableView->setColumnHidden(0, true);
secondtableView->setColumnHidden(2, true);
secondtableView->setColumnHidden(3, true);

QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(tableView);
layout->addWidget(secondtableView);

Upvotes: 3

Related Questions