漏网之鱼,QFileSystemModel中已经设置setFilter( QDir.Files),还是极少数目录被显示
其它目录正常
如果改成QListView(),没有日期等信息显示,纠结中,请高人指教!
import sys
import os
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 = QTreeView()
hlay.addWidget(self.treeview)
hlay.addWidget(self.listview)
#self.listview = QListView()#没有日期等信息
#path = QDir.rootPath()
path = ''
self.dirModel = QFileSystemModel()
#self.dirModel.setRootPath(QDir.rootPath())
self.dirModel.setRootPath('')
self.dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.fileModel = QFileSystemModel()
#self.fileModel.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.fileModel.setFilter( QDir.Files)
self.treeview.setModel(self.dirModel)
self.listview.setModel(self.fileModel)
self.listview.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.treeview.setColumnHidden(1, True)
self.treeview.setColumnHidden(2, True)
self.treeview.setColumnWidth(0, 500)
self.listview.setColumnWidth(0, 500)
self.treeview.setRootIndex(self.dirModel.index(path))
self.listview.setRootIndex(self.fileModel.index(path))
self.treeview.clicked.connect(self.on_clicked)
self.listview.clicked.connect(self.itemClicked)
def on_clicked(self, index):
path = self.dirModel.fileInfo(index).absoluteFilePath()
self.listview.setRootIndex(self.fileModel.setRootPath(path))
def itemClicked(self, Qmodelidx):
text = self.fileModel.data(Qmodelidx)
print(text)
indexItem = self.fileModel.index(Qmodelidx.row(), 0, Qmodelidx.parent())
#print(indexItem)
fileName = self.fileModel.data(indexItem)
print(fileName)
print(self.dirModel.filePath(Qmodelidx))
if name == '__main__':
app = QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…