QFileSystemModel disable QFileIconProvider

418 Views Asked by At

From looking around I've seen that the QFileIconProvider in the QFileSysetmModel can considerably slow things down. In my particular case I don't need it at all, but I can't find out how to easily just disable/remove it without causing a crash. This is my first time playing around with the model/view framework so it is possible the answer is quite simple and I just missed it in the documentation... but right now I can only find instances of sub-classing it, but no examples of getting rid of it altogether.

1

There are 1 best solutions below

1
On BEST ANSWER

The task that consumes a lot of time in the QFileIconProvider is to provide the icon since it has to load a file, etc. So a workaround for your case is to return a null QIcon:

import sys
from PyQt4 import QtCore, QtGui

class EmptyIconProvider(QtGui.QFileIconProvider):
    def icon(self, _):
        return QtGui.QIcon()

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    view = QtGui.QTreeView()
    model = QtGui.QFileSystemModel(view)
    model.setIconProvider(EmptyIconProvider())
    model.setRootPath(QtCore.QDir.currentPath())
    view.setModel(model)
    view.setRootIndex(model.index(QtCore.QDir.currentPath()))
    view.show()
    sys.exit(app.exec_())