仅显示具有正确扩展名的文件
我正在尝试在 QFileSystemModel 中仅显示扩展名为 *.txt
的文件,而其他类型则变为阴影/灰色:
proxy_
的类型为 QSortFilterProxyModelmodel_
的类型为 QFileSystemModel
这是我的代码:
proxy_->setFilterWildcard("*.txt");
proxy_->setSourceModel(model_);
model_->setNameFilters(QStringList(proxy_->filterRegExp().pattern()));
model_->setNameFilterDisables(true);
sel_model_ = (new QItemSelectionModel(proxy_));
treeView->setModel(proxy_);
treeView->setSelectionModel(sel_model_);
...但是这样做在我的视图中什么也没有显示。有人知道我做错了什么吗?
I'm trying in QFileSystemModel display just files with extention *.txt
and the other types shaded/grayed out:
proxy_
is of type QSortFilterProxyModelmodel_
is of type QFileSystemModel
Here's my code:
proxy_->setFilterWildcard("*.txt");
proxy_->setSourceModel(model_);
model_->setNameFilters(QStringList(proxy_->filterRegExp().pattern()));
model_->setNameFilterDisables(true);
sel_model_ = (new QItemSelectionModel(proxy_));
treeView->setModel(proxy_);
treeView->setSelectionModel(sel_model_);
...but by doing so nothing is shown in my view. Anyone knows what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
QFileSystemModel::setNameFilters
设置文件名过滤器。在下面的示例程序中,
.txt
和文件夹正常显示,其他文件被禁用(灰显)。nameFilterDisables
属性允许您选择禁用或隐藏已过滤的文件。You can set a file name filter with
QFileSystemModel::setNameFilters
.In the example program below
.txt
and folders are displayed normally, and other files are disabled (greyed out).The
nameFilterDisables
property allows you to choose between filtered out files being disabled or hidden.