Filter Columns in a QFileSystemModel

From Qt Wiki
Revision as of 15:26, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

How to Filter Columns in a QFileSystemModel

Sometimes one does not want to display all the columns of a QFileSystemModel [doc.qt.nokia.com], like discussed in this forum thread [developer.qt.nokia.com].

This can be achieved in two ways, either by hiding the columns in the view, by using a specialized proxy model. The easiest way is to hide the columns using the

QHeaderView

, but the alternative to subclass QSortFilterProxyModel [doc.qt.nokia.com] and reimplement the

filterAcceptsColumn()

method also works well.

Column hiding using QHeaderView

All multi-column views provide access to a QHeaderView [doc.qt.nokia.com] . This is the widget that provides the headers above the columns of data, and allows the user to resize those columns, or click the headers to trigger a sorting order. You can also use this widget to hide columns in your view.

The alternative method of using a custom proxy model is outlined below.

Column hiding using QSortFilterProxyModel

Be aware that the column count is 0-based and that it is hard coded.

fsmproxy.h

fsmproxy.cpp

Usage

Categories: