I'm trying to filter QFileSystemModel using QSortFilterProxyModel. But when I'm trying to do this my tableView doesn't show anything. Everything works correctly without using filter.

Qt Code:
  1. import sys
  2. from PyQt4 import QtCore, QtGui
  3.  
  4. class MyFileProxyModel(QtGui.QFileSystemModel):
  5.  
  6. def __init__(self):
  7. super(MyFileProxyModel, self).__init__(None)
  8. self.headers=['1','2','3','4']
  9.  
  10. def headerData(self, column, orientation, role):
  11. if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
  12. return QtCore.QVariant(self.headers[column])
  13.  
  14. return QtCore.QVariant()
  15.  
  16. class MyProxyFilter(QtGui.QSortFilterProxyModel):
  17.  
  18. def __init__(self):
  19. super(MyProxyFilter, self).__init__(None)
  20.  
  21. def filterAcceptsRow(self, sourceRow, sourceParent):
  22. return True
  23.  
  24. class MyMainWindow(QtGui.QWidget):
  25.  
  26. def __init__(self):
  27. super(MyMainWindow, self).__init__(None)
  28.  
  29. vl = QtGui.QVBoxLayout()
  30. tableView = QtGui.QTableView()
  31. tableView.setSortingEnabled(True)
  32.  
  33. vl.addWidget(tableView)
  34. self.setLayout(vl)
  35.  
  36. fileModel = MyFileProxyModel()
  37.  
  38. rootModelIndex = fileModel.setRootPath(QtCore.QDir.currentPath())
  39.  
  40. proxyFilter = MyProxyFilter()
  41. proxyFilter.setSourceModel(fileModel)
  42.  
  43. tableView.setModel(proxyFilter)
  44. tableView.setRootIndex(proxyFilter.mapFromSource(rootModelIndex))
  45.  
  46. if __name__ == '__main__':
  47. app = QtGui.QApplication(sys.argv)
  48. win = MyMainWindow()
  49. win.show()
  50. app.exec_()
  51. sys.exit()
To copy to clipboard, switch view to plain text mode