作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
使用PyKDE4.kio
选择多个文件我可以使用KFileDialog.getOpenFileNames
(而不是KFileDialog.getOpenFileName
)。如果要选择多个目录怎么办?只有 KFileDialog.getExistingDirectory
。
使用 KFileDialog.getOpenFileNames(filter = 'inode/directory')
并选择多个文件夹显示错误:
More than one folder has been selected and this dialog does not accept folders, so it is not possible to decide which one to enter. Please select only one folder to list it.
最佳答案
我从 JohannesMunk on qtcentre.org 找到了解决方案并将其翻译成 python
import sys
from PyQt5.QtWidgets import (QFileDialog, QAbstractItemView, QListView,
QTreeView, QApplication, QDialog)
class getExistingDirectories(QFileDialog):
def __init__(self, *args):
super(getExistingDirectories, self).__init__(*args)
self.setOption(self.DontUseNativeDialog, True)
self.setFileMode(self.Directory)
self.setOption(self.ShowDirsOnly, True)
self.findChildren(QListView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
self.findChildren(QTreeView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
qapp = QApplication(sys.argv)
dlg = getExistingDirectories()
if dlg.exec_() == QDialog.Accepted:
print(dlg.selectedFiles())
关于python - 如何使用 KFileDialog 选择多个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18707261/
使用PyKDE4.kio 选择多个文件我可以使用KFileDialog.getOpenFileNames(而不是KFileDialog.getOpenFileName)。如果要选择多个目录怎么办?只有
我是一名优秀的程序员,十分优秀!