Reputation: 327
I am trying to use QSortFilterProxyModel with QStandardItemmodel but filterAcceptedRows() is not updating the view.
The rows are correctly filetred in the function filterAcceptedRows() but the view is not updated. It is still displaying all the rows. Below you can find the code that i have already tried, could anybody tell me am i missing something here
This is the code in the QDialog.
m_modelApp = new QStandardItemModel();
m_proxyApp = new ProxyModelApp();
m_proxyApp->setSourceModel(m_modelApp);
m_lstApp->setModel(m_modelApp);
This is how i add data to the model.
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
QStandardItem *item3 = new QStandardItem();
QStandardItem *item4 = new QStandardItem();
QStandardItem *item5 = new QStandardItem();
QStandardItem *itemCheck = new QStandardItem();
item1->setData(l_sRefProduitSW,Qt::DisplayRole);
item2->setData("To Define",Qt::DisplayRole);
item3->setData(app.GetRefApp(),Qt::DisplayRole);
item4->setData(app.GetRefIdentApp(),Qt::DisplayRole);
item5->setData(app.GetRefFNRApp(),Qt::DisplayRole);
itemCheck->setCheckable(true);
if(m_xRefBe->GetListeAppBE().contains(app))
itemCheck->setCheckState(Qt::Checked);
else
itemCheck->setCheckState(Qt::Unchecked);
listItems<<itemCheck<<item1<<item2<<item3<<item4<<item5;
m_modelApp->appendRow(listItems);
One of the filter in the ProxyModelApp.
void ProxyModelApp::setRefLibApp(QString refLibApp){
if(m_refLibApp != refLibApp)
m_refLibApp = refLibApp;
invalidateFilter();
}
I would like to know, why after the successful filtering in the function filterAcceptedRows() does not update the view.
Thank you.
Upvotes: 1
Views: 1564
Reputation: 1590
Your table proxy model should be initialized in the following order
m_modelApp = new QStandardItemModel(); // Original model
m_proxyApp = new ProxyModelApp(); // Custome proxy model
m_proxyApp->setSourceModel(m_modelApp); // Proxy to original model.
m_lstApp->setModel(m_proxyApp); // Set the proxy model to the table view
Upvotes: 1
Reputation: 52621
You have the view use m_modelApp
- the original unfiltered model. You've created m_proxyApp
, but don't actually use it anywhere.
Upvotes: 1