qt - Unable to use QFileSystemModel along custom QSortFilterProxy -


i'm new qt , trying hide directories in qtreeview. i'm trying hide folders based on names using custom qsortfilterproxy named cachefilterproxy.

i setup tree view way:

filemodel = qtgui.qfilesystemmodel() rootindex = filemodel.setrootpath(rootdir) filemodel.setfilter(qtcore.qdir.dirs | qtcore.qdir.nodotanddotdot) filemodel.setnamefilters([patternstring]) model = cachefilterproxy() model.setsourcemodel(filemodel) self.filetreeview.setmodel(model) self.filetreeview.setrootindex(model.mapfromsource(rootindex)) self.filetreeview.clicked.connect(self.selectedfilechanged) 

and then, in self.selectedfilechanged try extract filename , filepath of selected item in tree view. name of file retrieved, retrieving file path causes whole program stop working , quit.

def selectedfilechanged(self, index):     filemodel = self.filetreeview.model().sourcemodel()     indexitem = self.filetreeview.model().index(index.row(), 0, index.parent())     # works normal     filename = filemodel.filename(indexitem)     # breaks entire program     filepath = filemodel.filepath(indexitem) 

this seems wrong. filemodelis source think index proxy index. think must map source model before using in filemodel.

def selectedfilechanged(self, proxyindex):     sourcemodel = self.filetreeview.model().sourcemodel()     sourceindex = self.filetreeview.model().maptosource(proxyindex)     sourceindexcol0 = sourcemodel.index(sourceindex.row(), 0, sourceindex.parent())      # works normal     filename = sourcemodel.filename(sourceindexcol0)     # breaks entire program     filepath = sourcemodel.filepath(sourceindexcol0) 

note renamed indexitem sourceindexcol0 index , not item. bit confusing @ first glance.

i not test code above. if doesn't work, verify indexes valid before using them , check model class.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -