Solved PyQt reset tableView
I am new to pyqt and using tableView in my application.
I am inserting rows to tableview. And I wish to clear the tableView(all row entries in table) once I push pushbutton.
Searched online, but could not find exact solution.
Could anyone help me in knowing how to clear rows in tableView or how to reset
tableview in pyqt.
What kind of model are you using with your qtableview ?
This post is deleted!
Thanks for quick reply
I am using QAbstractTableModel with qtableview
So when you say "clear the view"
do you want to delete the data from the model or simply
remove the whole model from the view?
The view only displays the data. and while it can filter it or sort it,
the model is the one that can clear the data.
If by clear you mean delete it.
Normally that would happen by removing the data from the original data structure
that is feeding the model.
I just don't want to display data in view.
Then just call setModel on view with null pointer.
It will then disconnect the model and show nothing.
actually I am trying to display certain set of rows in table based on key entered and when I enter new key in textedit and push button it should display the rows related to entered key
mrjj Lifetime Qt Champion last edited by mrjj
Hehe so that is very different from clearing the view.
You might want to use a proxy model to do the filtering.
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.
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.
@SGaist said in PyQt reset tabelView:
I am not using QSortFilterProxyModel
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 .
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.
No problem with that.