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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
回答2:
//filter treeview for directories and torrent files only
QStringList filters;
filters << "*.torrent";
QDirModel model = new QDirModel(this);
model->setReadOnly(true);
model->setSorting(QDir::DirsFirst |QDir::IgnoreCase | QDir::Type);
model->setFilter(QDir::AllDirs | QDir::AllEntries |QDir::NoDotAndDotDot);
model->setNameFilters(filters);
ui->treeView->setModel(model);