pyqt5 - QFileSystemModel 的图标功能在 Windows 上的 PyQt6 中是否损坏?
问题描述
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 IconProvider(QtGui.QFileIconProvider):
def icon(self, fileInfo):
if fileInfo.isDir():
return QtGui.QIcon("folder.png")
return QtGui.QFileIconProvider.icon(self, fileInfo)
对于 PyQt6,这将显示为目录提供的图标,但仍然不显示其他文件的图标
解决方案
推荐阅读
- python-3.x - 有没有办法从网站下载 csv 文件并使用 Lambda 将其直接上传到 Amazon S3?
- flutter - 从excel中获取数据到Datatable颤动
- r - 在图形点之外绘制形状轮廓
- git - remote add 仍然使用 --no-tags 选项获取标签
- c - memfd_secret():它应该如何工作?
- javascript - 如何在角度/打字稿中导入泛型?
- swiftui - 在返回导航上刷新 SwiftUI 视图
- python - 使用 SortValues 函数指示两列具有相同的值
- swift - SwiftUI 动画旋转故障@360/0 度标记
- reactjs - 在 yarn 工作区中共享组件(next 和 tailwindcss)