Solved PyQt reset tableView
-
@sushmita
Hehe so that is very different from clearing the view.You might want to use a proxy model to do the filtering.
https://doc.qt.io/qtforpython/PySide2/QtCore/QSortFilterProxyModel.htmlexample
https://stackoverflow.com/questions/14068823/how-to-create-filters-for-qtableview-in-pyqt -
Hi,
@mrjj ,Thanks for your suggestion, I tried using proxy model.
With this I can filter fields in same table view.But, I am trying to display the filtered data in different table view .
i.e one main table view will be showing all the entries, and once I enter the key, the filtered data is displayed in other table view.So while doing the same I am able to filter data and display in separate table view, but when I am entering new key and pushing button, the table view is displaying the new filtered data along with previous list.
I.e my need is to refresh the table view every time I enter key and push the button and display new filtered data.
Thanks,
Sushmita -
Hi,
Can you show the code related to the model and filtering ?
-
Sorry, but it is some internal code , and not supposed to share.
I have created two table views using QAbstractTableModel.
In 1st table view all entries and filtering data based on key entered and inserting the rows into 2nd model(table view). -
Why a custom table model ? Since you are using a QSortFilterProxyModel, just assign that one to the view showing the filtered data. There's no need for that second model.
-
-
Sorry, I misunderstood your answer to @mrjj.
In any case, that would likely be the solution. You have a view on your complete data, then on the filtered view, you put the QSortFilterProxyModel as model on top of your main data. That way you don't have to manually add/remove stuff from a secondary model that would duplicate the data already available.
-
Ok. Thanks .
I thought of trying without using QSortFilterProxyModel
I will try . -
Hi,
Can we use QSortFilterProxyModel with QAbstractTableModel?
Cause the example which was suggested proxy model I referred is using QStandardItemModel.But in my application I am usign QAbstractTableModel for data model.
Thanks,
Sushmita -
No problem with that.