Search code examples
qtqt4qtreeviewqtreewidget

one type of file format in QTreeView


Is it possible to set only one file format visible to the user? I'm searching it in documentation, but I can't find it... If not, which other widget you are suggesting to use?


Solution

  • I assume you're using a QTreeView with a QFileSystemModel. If not, I'd suggest doing so. QTreeWidget is not as flexible.

    QFileSystemModel has a method called setNameFilters that should do what you want. To use it, do something like this:

    QStringList filters;
    filters.append("*.cc"); // whatever filters you want
    filters.append("*.h");
    
    QFileSystemModel *model = new QFileSystemModel;
    model->setNameFilters(filters);
    
    QTreeView *view = new QTreeView;
    view->setModel(model);