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.
Asked
Active
Viewed 367 times
1
-
What actual evidence do you have that the alleged performance issues will affect your application? – ekhumoro Nov 09 '18 at 00:25
-
@ekhumoro Didn't benchmark it myself, just from what I saw on a few other SO posts (sorry, don't still have the link). – Spencer Nov 09 '18 at 00:46
1 Answers
1
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_())

eyllanesc
- 235,170
- 19
- 170
- 241
-
You know I had this idea, but wasn't quite sure how to implement it. Works perfectly! And in my purely un-scientific observational test cases, it's running much more quickly! – Spencer Nov 09 '18 at 00:45