QSortFilterProxyModel - refresh TreeNode on delete/add
-
Hi ,
I have developed a model based on QSortFilterProxyModel and so far it works well. I have an option called 'Refresh Folder' in Contextmenu of the QTreeView.Refresh Folder- needs to updates the parent TreeNode with newly added child Nodes (reading from the disk at particular location).
When i filter nodes based on some regular expression it displays desired Nodes. In the mean while i want to refresh/Reload/update the folder node if there are any new files exists at parent directory then i have to update the Parent TreeNode and filter it again as user typed filtered text.
But in my case , When the user tries to refresh a Parent TreeNode when it is in filtered mode TreeView displays duplicate Nodes.How to solve this?/////
Note: QTreView allows Updates/Refresh/Reload a perticular Folder Node properly when there is no filtered text
How to update/Refresh a Folder TreeNode when Filter is on?
-
Hi Girolf,
In my 'RefreshFolder' method inside treeview class which inherits QTreeView and here is the code.
please let me know if you need more info.@def RefreshFodler(self):
model=self.model()
index=self.selectionModel().currentIndex()
data=self.getData(index) # returns custom data with
item=self.originalmodel.itemFromIndex(index)
model.removeRows(0,item.rowCount(),index)
""" here i am reading files from disk and updating the item"""
files=self.getFiles()
self.setupModelData(files,item)#---adds file to parent-item
item.sort(0,QtCore.Qt.AscendingOrder)
self.update()
if item.hasChildren():
self.expand(index)def getData(self,index):
index=self.sortmodel.mapToSource(index)
item=self.originalmodel.itemFromIndex(index)
return item.data(0,QtCore.Qt.UserRole)@