QFileDialog 中的多个文件和文件夹选择?
我正在使用 pyQt4,希望在 GUI 中有一个浏览按钮,该按钮打开一个对话框,允许用户选择多个文件和文件夹。 我已经研究了很多,但没有找到任何方法可以做到这一点。
QFileDialog.getOpenFileNames() 只允许我选择文件,而 QFileDialog.getExistingDirectory() 只允许选择目录。
有什么办法可以将它们的功能结合起来吗? 理想情况下,我想使用 nativeDialogs 但这似乎不可能。 因此,我愿意在外观上做出妥协。有什么办法可以实现我所说的吗?
同样的问题也在这里被问到,但答案是在 c++ 中。我需要一个 python 实现。 允许用户选择文件或文件夹QFileDialog
I am using pyQt4 and want to have a Browse button in my GUI which opens up a Dialog box allowing user to select multiple files AND folders.
I have researched quite a bit but din't find any way to be able to do this.
The QFileDialog.getOpenFileNames() only allows me to choose files and QFileDialog.getExistingDirectory() only allows to choose directories.
Is there any way I can somehow combine their functionality.
Ideally I would like to use the nativeDialogs but that doesn't seem to be possible.
As a result I am willing to compromise on the looks. Is there any way I can implement the said?
The same question has been asked here as well but the answer is in c++. I need a python implementation.
Allow user to select a file or a folder in QFileDialog
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个应该适合您的技巧:创建 QFileDialog 的子类,断开“打开”按钮并将其重新连接到自定义函数。不过,它不能保证在不同版本的 Qt 上工作,因为它依赖于找到可能在某个时刻重新配置的特定子小部件。
Here's a hack that should work for you: Create a subclass of QFileDialog that disconnects the "Open" button and reconnects it to a customized function. It's not guaranteed to work across different versions of Qt, though, since it relies on being able to find specific sub-widgets that may be reconfigured at some point.
在 Qt5 中你可以简单地使用
In Qt5 you can simply use