How to refresh treeview when QFileSystemModel's filterList changed?
i used a lineEdit to get filename filter from user, so when the text changed, i update the Namefilter of QFileSystemModel, but i must collpse current dir and expand it again to refresh file list. so ,why does treeview not refreshed when model is updated?
thx in advance , sry for my english
Re: How to refresh treeview when QFileSystemModel's filterList changed?
Please provide a minimal compilable example reproducing the problem.
Re: How to refresh treeview when QFileSystemModel's filterList changed?
Code:
self.connect(self.findEdit, QtCore.SIGNAL("textChanged(const QString&)"),self.dirView.onFilterChanged)
def __init__(self, dataSource):
self.model = QtGui.QFileSystemModel(self)
self.loadExtensionFilter()
self.
model.
setFilter(QDir.
AllDirs|QDir.
Files |
QDir.
NoDotAndDotDot) self.model.setRootPath("/")
self.setModel(self.model)
def onFilterChanged(self,str):
self.filterList.clear()
for ext in self.extFilterList:
self.filterList.append(ext)
else:
self.filterList.clear()
for ext in self.extFilterList:
self.
filterList.
append(QString("*"+ str
) + ext
)
self.model.setNameFilters(self.filterList)
so after i set new Filters by method setNameFilters(), the model is updated, but the treeview did not refresh.
Re: How to refresh treeview when QFileSystemModel's filterList changed?
i tried QDirModel ,it worked fine, why treeview with QFileSystemModel can't refresh?
Re: How to refresh treeview when QFileSystemModel's filterList changed?
Did the model really refresh?
Re: How to refresh treeview when QFileSystemModel's filterList changed?
the model's NameFilters has changed( i print them after setNameFilters() ensure this ), but treeview did not refresh.
Re: How to refresh treeview when QFileSystemModel's filterList changed?
I'm asking whether the model's data changed not whether the object's property value changed. The view probably didn't refresh because the model didn't change.
Re: How to refresh treeview when QFileSystemModel's filterList changed?
sry for my misunderstanding ,the model's data did not changed, but when i change QFileSystemModel to QDirModel, treeview refreshed after NameFilters changed
Re: How to refresh treeview when QFileSystemModel's filterList changed?
Maybe QDirModel refreshes itself after name filters is changed and QFileSystemModel doesn't. I think it's high time to go beyond "it doesn't work for me" state. As for now you don't even know what doesn't work so how do you expect us to help you.
Re: How to refresh treeview when QFileSystemModel's filterList changed?
thx for your patient.
Quote:
QDirModel refreshes itself after name filters is changed and QFileSystemModel doesn't
i think this is why treeview did not refresh, i tried two ways to refresh treeview:
1. make a new instance of QFileSystemModel, setModel this new instance and restore treeviews state, (it's a bit lag to restore expanded nodes, and it's a bit hard to restore node which colume number other than 0 )
2. refresh the model Manually: i tried emit signal dataChanged() of model(give current index to it), but treeview did not refresh, may be i need to emit every node's dataChanged() signal
Re: How to refresh treeview when QFileSystemModel's filterList changed?
Name filters is a filter method applied to existing nodes, it does not cause the whole model to be repopulated with new data. If you applied a name filter and it didn't change the data available in the model then it means the new filter reveals the same set of data as the old one. Which points us to a conclusion that you are doing something wrong in your code which causes two different filters to have the same result.