<p>I have a <code>QDirModel</code> whose current directory is set. Then I have a <code>QListView</code> which is supposed to show the files in that directory. This works fine.</p>

<p>Now I want to limit the files shown, so it only shows <em>png</em> files (the filename ends with .png). The problem is that using a <code>QSortFilterProxyModel</code> and setting the filter regexp will try to match every parent of the files as well. According to the documentation:</p>

<blockquote>
  <p>For hierarchical models, the filter is
  applied recursively to all children.
  If a parent item doesn't match the
  filter, none of its children will be
  shown.</p>
</blockquote>

<p>So, how do I get the <code>QSortFilterProxyModel</code> to only filter the files in the directory, and not the directories it resides in?</p>

We ran into something similar where I work, and ended up making our own proxy model to do our filtering.  However, looking through the documentation for what you want (which seems like it would be a more common case), I came across two possibilities.
You might be able to set a name filter on the QDirModel and filter things that way.  I have no idea if this will work like you want, or if the name filters apply to directories also.  The documentation is kind of sparse on these.
Subclass the QSortFilterProxyModel and override the
```
filterAcceptsRow
```
function.  From the documentation:
Custom filtering behavior can be achieved by reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions.
Then you could presumably use the model index to check if the index item is a directory (automatically accept) or a file (filter on filename).