我尝试创建自己的QFileIconProvider
类,我想将其用于QFileSystemModel
. 我最终得到了这段代码:
class SeIconProvider(QtGui.QFileIconProvider):
def __init__(self):
QtGui.QFileIconProvider.__init__(self)
self.rsFileIcon = QtGui.QIcon(':images/rs-file.png')
self.otherFileIcon = QtGui.QIcon(':images/newfile.png')
self.folderIcon = QtGui.QIcon(':images/openFolder.png')
def icon(self, type):
if type == self.File:
return self.rsFileIcon
if type == self.Folder:
return self.folderIcon
return self.otherFileIcon
def icon(self, info):
if info.isFile():
return self.otherFileIcon
if info.isDir():
return self.folderIcon
return self.otherFileIcon
def type(self, info):
if info.isDir():
return 'Directory'
return 'File'
class FolderView(QtGui.QTreeView):
def __init__(self):
QtGui.QTreeView.__init__(self)
self.createComponents()
self.createLayout()
def createComponents(self):
self.model = QtGui.QFileSystemModel()
self.model.setIconProvider(SeIconProvider())
self.setModel(self.model)
def createLayout(self):
self.setHeaderHidden(True)
现在我的问题是树视图中不仅没有显示任何图标,而且代码也没有抛出任何异常。有人知道我做错了什么吗?