Don't show hidden files with QFileSystemModel
-
-
@ivanicy Yes, just spend a minute to read the link a gave you then you will also see https://doc.qt.io/qt-5/qdir.html#Filter-enum
-
@ivanicy said in Don't show hidden files with QFileSystemModel:
.cache
This is a hidden file/folder on UNIX/Linux, so QDir::Hidden is what you need...
-
@ivanicy
QDir::Hidden
means files/directories beginning with.
under Linux but with Hidden attribute under Windows. If you are under Windows and a file/directory starts with a.
(and does not have Hidden attribute set) you will need to write code to exclude it.Having said that, I do not actually see in
QFileSystemModel
any facility for you to exclude/filter out file names starting with.
under Windows. I don't think thesetNameFilters()
method will let you achieve that.You might instead achieve the filtering/exclusion for the purpose of not viewing such files/directories by, say, interposing some
QAbstractProxyModel
between yourQFileSystemModel
and whatever view you attach, e.g. QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern) or sub-classed bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const, could be used to exclude items starting with a.
in their name. I note that e.g. https://stackoverflow.com/questions/11454248/how-to-exclude-dirs-in-qfilesystemmodel says to do just this sort of thing. Similarly the comment in https://stackoverflow.com/a/4927222/489865 points you to https://stackoverflow.com/questions/4893122/filtering-in-qfiledialog which also takes the same approach. -
What about such option as show hidden files mac?