0

I have tried few attempt to show only file names inside my folder and subfolder but no luck so far. Basically below is how my QTreeview looks like

enter image description here

Here, Folder structure is like :-

SV
  A_XML_Folder
   A_XML_Folder.xml
  B_XML_Folder
   B_XML_Folder.xml
SI
  A_Python_Folder
   A_Python_Folder.py
  B_Python_Folder
   B_Python_Folder.py

So far so good, but now i am only keen to get list of python and xml files like

A_XML_Folder.xml
B_XML_Folder.xml
A_Python_Folder.py
B_Python_Folder.py

My code is :

        self.mymodel.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot | QDir.AllEntries) #QDir.AllDirs | 
        self.mymodel.setNameFilters(["*.py","*.xml"])
        self.mymodel.setNameFilterDisables(False)
        self.mymodel.setRootPath(QDir.currentPath()+'/Database')

        self.ui.treeView.setModel(self.mymodel)
        self.ui.treeView.setRootIndex(self.mymodel.index(QDir.currentPath()+'/Database'))
        self.ui.treeView.setSortingEnabled(True)
        self.ui.treeView.hideColumn(1)
        self.ui.treeView.hideColumn(2)
        self.ui.treeView.hideColumn(3)
        self.ui.treeView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
        self.ui.treeView.setAnimated(True)

I tried all permo-combo but no luck so far, is there any other elegant way for the problem

Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21
  • If I understand correctly you want a model that searches all files in a directory tree and presents them as a list. I don't think `QFileSystemModel` offers this functionality. I recommend that you implement your own model by subclassing `QAbstractListModel`. – titusjan Jul 26 '17 at 06:26
  • Yes titisjan, i did the same and now i am using QListView with QStandardItemModel and filling it with all xml and py files using os.walk. I will soon upload the answer. Thanks – Pawankumar Dubey Jul 27 '17 at 07:45

0 Answers0