Python pyqt5:具有多个根qtreeview
我尝试创建一个带有Qtreeview窗口的pyqt5窗口来加载某些文件 我需要在同一个Qtreeview中显示来自不同位置的多个目录作为根文件夹,因此这意味着我需要在同一个Qtreeview中有多个根(或伪造) 无法更改目录结构 我读过,但它不符合我的需要,因为要排除的文件夹数量将是巨大的(今天超过10000个文件夹),而且每天都会增加 “include”函数更可行,但我不知道如何这样做 这是我目前为“path1”工作的代码:Python pyqt5:具有多个根qtreeview,python,pyqt5,Python,Pyqt5,我尝试创建一个带有Qtreeview窗口的pyqt5窗口来加载某些文件 我需要在同一个Qtreeview中显示来自不同位置的多个目录作为根文件夹,因此这意味着我需要在同一个Qtreeview中有多个根(或伪造) 无法更改目录结构 我读过,但它不符合我的需要,因为要排除的文件夹数量将是巨大的(今天超过10000个文件夹),而且每天都会增加 “include”函数更可行,但我不知道如何这样做 这是我目前为“path1”工作的代码: import sys from PyQt5.QtWidgets i
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Widget(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
hlay = QHBoxLayout(self)
self.treeview = QTreeView()
self.listview = QListView()
hlay.addWidget(self.treeview)
hlay.addWidget(self.listview)
path1 = "/mnt/volume1/somedirectory/root1" #QDir.rootPath()
path2 = '/mnt/volume2/root2'
self.dirModel = QFileSystemModel()
self.dirModel.setRootPath(QDir.rootPath())
self.dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.fileModel = QFileSystemModel()
self.fileModel.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.treeview.setModel(self.dirModel)
self.listview.setModel(self.fileModel)
self.treeview.setRootIndex(self.dirModel.index(path1))
self.listview.setRootIndex(self.fileModel.index(path1))
self.treeview.clicked.connect(self.on_clicked)
def on_clicked(self, index):
path1 = self.dirModel.fileInfo(index).absoluteFilePath()
self.listview.setRootIndex(self.fileModel.setRootPath(path1))
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
我的问题是:如何在不手动排除大量文件夹的情况下,将“path1”和“path2”作为根(或给人留下印象)