gpt4 book ai didi

qt - 将 QSortFilterProxyModel 与树模型一起使用

转载 作者:行者123 更新时间:2023-12-01 19:06:06 25 4
gpt4 key购买 nike

我有一个QDirModel,其当前目录已设置。然后我有一个 QListView ,它应该显示该目录中的文件。这工作得很好。

现在我想限制显示的文件,因此它只显示 png 文件(文件名以 .png 结尾)。问题是使用 QSortFilterProxyModel 并设置过滤器正则表达式也会尝试匹配文件的每个父级。根据文档:

For hierarchical models, the filter is applied recursively to all children. If a parent item doesn't match the filter, none of its children will be shown.

那么,如何让 QSortFilterProxyModel 只过滤目录中的文件,而不过滤它所在的目录?

最佳答案

从 Qt 5.10 开始,QSortFilterProxyModel 可以选择递归过滤。换句话说,如果子级与过滤器匹配,则其父级也将可见。

查看QSortFilterProxyModel::recursiveFilteringEnabled .

关于qt - 将 QSortFilterProxyModel 与树模型一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/250890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com