允许用户在 QFileDialog 中选择文件或文件夹
在 PyQt 中,您可以执行类似以下操作来允许用户选择文件,
filename = QtGui.QFileDialog.getOpenFileName(self, "Choose file..")
但是我希望打开一个 QFileDialog,用户可以在其中选择文件或目录。我确信我以前在 PyQt 应用程序中见过这个功能,但我似乎找不到任何方法来做到这一点。
In PyQt you can do something like the following to allow the user to select a file
filename = QtGui.QFileDialog.getOpenFileName(self, "Choose file..")
However I would like a QFileDialog
to open in which the user would be able to select either a file or a directory. I'm sure I've seen this feature in PyQt applications before, but I can't seem to find any way to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我记得,您需要编写自己的 QFileDialog 并设置正确的 模式。我相信这应该是 QFileDialog.ExistingFile & QFileDialog.Directory。
您可以尝试基于 getExisitingDirectory (来自 C++ 存储库)编写自己的静态方法:
From what I remember you need to write your own QFileDialog and set proper mode. I believe this should be
QFileDialog.ExistingFile & QFileDialog.Directory
.You can try to write your own static method basing on the getExisitingDirectory (from C++ repository):