QFileSystemModel 中的文件是灰色的
我使用以下过滤器设置 QFileSystemModel:
QDir::Filters( Dirs|AllDirs|Files|Drives|NoDotAndDotDot|AllEntries )
在我的代理模型中,我使用正则表达式按名称过滤文件:
proxy_model_->setFilterRegExp(".*\\.(cpp$|cxx$|c$|hpp$|h$)");
....然后我的 model_
是 QFileSystemModel,我有line:
model_->setNameFilters(QStringList(proxy->filterRegExp().pattern()));
...但是显示的文件是灰色的。为什么以及如何使它们“正常”。
I'm setting my QFileSystemModel with following filters:
QDir::Filters( Dirs|AllDirs|Files|Drives|NoDotAndDotDot|AllEntries )
In my proxy model, I am using a regular expression to filter files by name:
proxy_model_->setFilterRegExp(".*\\.(cpp$|cxx$|c$|hpp$|h$)");
....and then where my model_
is a QFileSystemModel, I have the line:
model_->setNameFilters(QStringList(proxy->filterRegExp().pattern()));
...yet files displayed are greyed out. Why, and how to make them "normal".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QFileSystemModel 使用的“名称过滤器”没有很好的文档记录。但我假设它们可能与 QFileDialog 在其 setNameFilter(s) 中使用的格式相同:
http://doc.qt.nokia.com/stable/qfiledialog.html#setNameFilter
如果是这样,则这些不是正则表达式。它们是一种奇怪的文本格式,后跟包含命令行终端样式通配符的括号。
所以我猜这会起作用:
一般来说,除非文档或函数名称另有说明,否则我会小心地假设将过滤器作为 QString 的地方会知道如何构成正则表达式!
The "name filters" that are used by the QFileSystemModel aren't very well documented. But I'm going to assume they're probably the same format as the ones used by the QFileDialog in its setNameFilter(s):
http://doc.qt.nokia.com/stable/qfiledialog.html#setNameFilter
If so, those aren't regular expressions. They're an odd format of text, followed by parentheses containing command-line-terminal-style wildcards.
So I'm guessing this would work:
In general, unless documentation or the name of the function indicates otherwise, I'd be careful to assume that places that take filters as a QString would know what to make of a regular expression!
实际上,不同的Qt类之间的格式是不一致的。如果他们采用单个 QString,那么就像 @HostileFork 所说的那样。然而,在这种情况下,函数 setNameFilters() 采用 QStringList,这意味着你想要:
由于你的输入格式错误(正则表达式,而不是 Window 的通配符),所以所有内容都被标记为“过滤掉”,因为没有任何内容与奇怪的语法匹配。
为什么变灰了?因为 QFileSystemModel 默认情况下禁用/灰显被过滤的文件(bwah?),而不是隐藏它们。这可以通过调用来更改:
QFileSystemModel's 'nameFilterDisables' 属性
Actually, the format is inconsistent between different Qt classes. If they take a single QString, then it's as @HostileFork says. In this case, however, the function setNameFilters() takes a QStringList, which means you want:
Since your input was the wrong format (regex, instead of Window's wildcards), everything was marked as "filter this out" because nothing matched the weird syntax.
Why greyed out? Because QFileSystemModel by default disabled/greys-out files that get filtered (bwah?), instead of hiding them. This can be changed by calling:
QFileSystemModel's 'nameFilterDisables' property