PDA

View Full Version : How to refresh treeview when QFileSystemModel's filterList changed?



vertusd
23rd November 2010, 08:31
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

wysota
23rd November 2010, 10:00
Please provide a minimal compilable example reproducing the problem.

vertusd
24th November 2010, 01:08
self.connect(self.findEdit, QtCore.SIGNAL("textChanged(const QString&)"),self.dirView.onFilterChanged)


class DirView(QtGui.QTreeView):
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):
if str==QString(""):
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.

vertusd
24th November 2010, 07:25
i tried QDirModel ,it worked fine, why treeview with QFileSystemModel can't refresh?

wysota
24th November 2010, 08:36
Did the model really refresh?

vertusd
24th November 2010, 10:08
the model's NameFilters has changed( i print them after setNameFilters() ensure this ), but treeview did not refresh.

wysota
24th November 2010, 10:35
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.

vertusd
24th November 2010, 11:38
sry for my misunderstanding ,the model's data did not changed, but when i change QFileSystemModel to QDirModel, treeview refreshed after NameFilters changed

wysota
24th November 2010, 18:50
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.

vertusd
25th November 2010, 01:19
thx for your patient.


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

wysota
25th November 2010, 11:33
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.