QFileSystemModel::headerData() is hard coded to return translated versions of "Name", "Size", "Type" or "Kind" and there is no implementation of setHeaderData(). You could use a simple subclass of QFileSystemModel. Something like:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class FileSystemModel(QtGui.QFileSystemModel):
def __init__(self):
QtGui.QFileSystemModel.__init__(self)
def headerData(self, section, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
if section == 0:
result = self.tr('Foo')
elif section == 1:
result = self.tr('Bar')
elif section == 2:
result = self.tr('Baz')
elif section == 3:
result = self.tr('Bob')
else:
else:
result = super(QtGui.QFileSystemModel, self).headerData(section, orientation, role)
return result
def main():
m = FileSystemModel()
m.setRootPath('/')
w.setModel(m);
w.resize(640, 480)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class FileSystemModel(QtGui.QFileSystemModel):
def __init__(self):
QtGui.QFileSystemModel.__init__(self)
def headerData(self, section, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
if section == 0:
result = self.tr('Foo')
elif section == 1:
result = self.tr('Bar')
elif section == 2:
result = self.tr('Baz')
elif section == 3:
result = self.tr('Bob')
else:
result = QtCore.QVariant()
else:
result = super(QtGui.QFileSystemModel, self).headerData(section, orientation, role)
return result
def main():
app = QtGui.QApplication(sys.argv)
m = FileSystemModel()
m.setRootPath('/')
w = QtGui.QTreeView()
w.setModel(m);
w.resize(640, 480)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
To copy to clipboard, switch view to plain text mode
Bookmarks