QFileSystemModel and QSortFilterProxyModel problem
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.
Code:
import sys
from PyQt4 import QtCore, QtGui
class MyFileProxyModel(QtGui.QFileSystemModel):
def __init__(self):
super(MyFileProxyModel, self).__init__(None)
self.headers=['1','2','3','4']
def headerData(self, column, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.
QVariant(self.
headers[column
])
def __init__(self):
super(MyProxyFilter, self).__init__(None)
def filterAcceptsRow(self, sourceRow, sourceParent):
return True
def __init__(self):
super(MyMainWindow, self).__init__(None)
tableView.setSortingEnabled(True)
vl.addWidget(tableView)
self.setLayout(vl)
fileModel = MyFileProxyModel()
rootModelIndex
= fileModel.
setRootPath(QtCore.
QDir.
currentPath())
proxyFilter = MyProxyFilter()
proxyFilter.setSourceModel(fileModel)
tableView.setModel(proxyFilter)
tableView.setRootIndex(proxyFilter.mapFromSource(rootModelIndex))
if __name__ == '__main__':
win = MyMainWindow()
win.show()
app.exec_()
sys.exit()