Пожалуйста, посмотрите, подойдет ли вам приведенный ниже пример:
import sys
from PyQt4 import QtGui, QtCore
class TestSortFilterProxyModel(QtGui.QSortFilterProxyModel):
def __init__(self, parent=None):
super(TestSortFilterProxyModel, self).__init__(parent)
self.filter = ['folder0/file0', 'folder1/file1'];
def filterAcceptsRow(self, source_row, source_parent):
index0 = self.sourceModel().index(source_row, 0, source_parent)
filePath = self.sourceModel().filePath(index0)
for folder in self.filter:
if filePath.startsWith(folder) or QtCore.QString(folder).startsWith(filePath):
return True;
return False
class MainForm(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
model = QtGui.QFileSystemModel(self)
model.setRootPath(QtCore.QDir.currentPath())
proxy = TestSortFilterProxyModel(self)
proxy.setSourceModel(model)
self.view = QtGui.QTreeView()
self.view.setModel(proxy)
self.setCentralWidget(self.view)
def main():
app = QtGui.QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
main()
надеюсь, это поможет, с уважением