如何在 qfiledialog 中设置目录过滤器

发布于 2024-08-30 17:14:45 字数 401 浏览 4 评论 0原文

我想知道是否有任何方法可以使用 QFileDialog 类一次仅选择某些目录和某些文件。这里我设置了文件过滤器,但我还需要设置文件夹过滤器。我有一些文件夹的名称中带有“扩展名”(例如 name.abc、flight.abc 等),并且我希望仅根据

我当前使用的

QStringList files = QFileDialog::getOpenFileNames(this, tr("Files & Directories"), QDir::currentPath(),tr("*.doc*.txt") );

名称来选择此类文件夹tr(" *.doc*.txt") 是我的文件过滤器。以同样的方式,我需要最后仅包含名称 .abc 的文件夹过滤器。

I would like to know is there any way to select only some directories and some files at a time using QFileDialog class. Here I set filesfilter but I also need to set folder filter. I have folders which have sort of "extension" in their name (e.g. name.abc,flight.abc etc) and I want only such folders to be selected on the basis of their name

I'm currently using

QStringList files = QFileDialog::getOpenFileNames(this, tr("Files & Directories"), QDir::currentPath(),tr("*.doc*.txt") );

tr("*.doc*.txt") is my files filter. In the same way I need folders filter with name only .abc at the end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2024-09-06 17:14:45

看起来您需要对打开文件对话框使用代理模型。看一下 QFileDialog::setProxyModel() 以及Qt 模型/视图编程。

It looks like you need to use proxy model for the open file dialog. Take a look on the QFileDialog::setProxyModel() and documentation of the Qt Model/View programming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文