<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>hey guys,<br>....I've read all the documentation and for the life of me, I can't find the<br>solution to initiate simple file filtering (by extension) in QFileSystemModel,<br>and/or using QDirModel / QDir...<br><br>I just want a Treeview of files and directory, but excluding certain files by<br>their extension....seems pretty simple, right?....<sigh>...<br>Thanks for any help,...<br><br>Here's my code:<br><br># --------------------------------------<br><br>#!/usr/bin/python<br><br><br>from PyQt4 import QtGui<br>from PyQt4 import QtCore<br><br>from PyQt4.QtCore import (QDate, QFile, QFileInfo, QIODevice, QString, QStringList, QDir, QTextStream, Qt, SIGNAL)<br><br><br><br><br>if __name__ == '__main__':<br><br> import sys<br><br> app = QtGui.QApplication(sys.argv)<br><br> startDir =
QString("")<br> startDir = "C:/library/stuff"<br><br> filter = QStringList("")<br> filter = ("JPG (*.jpg)");<br><br><br> #model = QtGui.QDirModel()<br> model = QtGui.QFileSystemModel()<br> model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot | QDir.AllEntries)<br> model.setNameFilters(filter)<br> model.setNameFilterDisables(0)<br> model.setRootPath(startDir)<br><br> tree = QtGui.QTreeView()<br> tree.setModel(model)<br><br><br> #setDir = QtCore.QDir(startDir)<br> #setDir.setNameFilters(filter)<br> #tree.setRootIndex(model.index(QtCore.QDir.path(setDir), 0 ))<br><br><br> tree.setAnimated(False)<br> tree.setIndentation(20)<br>
tree.setSortingEnabled(True)<br><br> tree.setWindowTitle("Dir View")<br> tree.resize(640, 480)<br> tree.show()<br><br> sys.exit(app.exec_())<br><br><br># ---------------------------------------------------<br></td></tr></table><br>