title: Display folders/files with different icons in QTreeView
body: <p>I have written a function in Python which goes through a specified directory and gets all its files and sub-folders recursively and filtering it to only list certain file formats. How do I display this in a treeview with an different icon for folders vs files?</p>
  
  <p><strong>recursive directory function:</strong></p>
  
  <pre><code>def test(self):
      formats = ['.jpg', '.jpeg', '.txt']
  
      for path, subdirs, files in os.walk(r'C:/Users/jmartini/Projects/Photogrammetry'):
          for file in files:
              filename, extension = os.path.splitext(file)
  
              if (extension.lower() in formats):
                  f = os.path.join(path, file)
                  print f
  </code></pre>
  
  <p><strong>Concept</strong></p>
  
  <p><a href="https://i.stack.imgur.com/LdVfQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LdVfQ.png" alt="enter image description here"></a></p>
  
  <p><strong>Entire application code:</strong></p>
  
  <pre><code>import sys
  import os
  from PySide import QtGui, QtCore
  
  
  class Example(QtGui.QWidget):
  
      def __init__(self):
          super(Example, self).__init__()
          self.initUI()
  
      def initUI(self):      
          # formatting
          self.resize(550, 400)
          self.setWindowTitle("Toychest")
  
          # widgets
          self.toollist = QtGui.QTreeView()
  
          # Tabs
  
          # signals
  
          # main layout
          mainLayout = QtGui.QGridLayout()
          mainLayout.setContentsMargins(0,0,0,0)
          mainLayout.addWidget(self.toollist)
          self.setLayout(mainLayout)
  
          # self.test()
  
  # Functions
  # ------------------------------------------------------------------------------
      def test(self):
          formats = ['.jpg', '.jpeg', '.txt']
  
          for path, subdirs, files in os.walk(r'C:/Users/jmartini/Projects/Photogrammetry'):
              for file in files:
                  filename, extension = os.path.splitext(file)
  
                  if (extension.lower() in formats):
                      f = os.path.join(path, file)
                      print f
  
  
  # Main
  # ------------------------------------------------------------------------------
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      ex.show()
      sys.exit(app.exec_())
  </code></pre>