How To Select Multiple Directories With Kfiledialog?
With PyKDE4.kio to select multiple files I can use KFileDialog.getOpenFileNames (instead of KFileDialog.getOpenFileName). What can I do if I want to select multiple directories? Th
Solution 1:
I found a solution from JohannesMunk on qtcentre.org and translated it to 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())
Post a Comment for "How To Select Multiple Directories With Kfiledialog?"