问题描述
PyQt5 代码:
from PyQt5.QtWidgets import QApplication,QFileSystemModel,QTreeView
from pathlib import Path
app =QApplication([])
model = QFileSystemModel()
cwd_str = f'{Path.cwd()}'
model.setRootPath(cwd_str)
treeview = QTreeView()
treeview.setModel(model)
root_idx = model.index(cwd_str)
treeview.setRootIndex(root_idx)
treeview.show()
app.exec()
PyQt6 代码:
from PyQt6.QtGui import QFileSystemModel
from PyQt6.QtWidgets import QApplication,QTreeView
from pathlib import Path
app =QApplication([])
model = QFileSystemModel()
cwd_str = f'{Path.cwd()}'
model.setRootPath(cwd_str)
treeview = QTreeView()
treeview.setModel(model)
root_idx = model.index(cwd_str)
treeview.setRootIndex(root_idx)
treeview.show()
app.exec()
我已经明确尝试设置 QFileIconProvider:(来自 PyQt QFileIconProvider class custom icons)
class IconProvider(QtGui.QFileIconProvider):
def icon(self,fileInfo):
if fileInfo.isDir():
return QtGui.QIcon("folder.png")
return QtGui.QFileIconProvider.icon(self,fileInfo)
对于 PyQt6,这将显示为目录提供的图标,但仍不显示其他文件的图标
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)