I am a beginner with the QFileSystemModel class and still trying to figure it out. I would like to create a custom file browser. I dug up enough code online to find out how to populate a QTableView with the folder contents of a specified root path. However, I was wondering how I might be able to insert additional rows of data into this model (something other than the files and folders that are already listed there). These rows could contain random words, icons, etc. Is this possible?

The only potential method I saw described in the docs is QFileSystemModel's .setData(). But I am not sure how to use it. It looks like I need to pass a few arguments into it in order to use it: QModelIndex , a QVariant value, and a role. Are all of these arguments mandatory? I don't completely understand the QModelIndex class and how to use it. Is this class always needed in order to get and set table data? I have used QTableWidgets before, but I would use QTableWidgetItem's for getting and setting. Does QModelIndex essentially play the same role as QTableWidgetItem?
Could anyone provide some example code as to how to insert a row of arbitrary text, etc into QFileSystemModel?

This is the code I have to so far for creating the model and table. It works fine, and displays all of the files and folders in specified directory. (it's in PyQt....but I certainly don't mind any C++ examples) Thanks!!


Qt Code:
  1. class Main(QtGui.QWidget):
  2. def __init__(self, *args):
  3. super(Main, self).__init__(*args)
  4.  
  5. layout = QtGui.QHBoxLayout()
  6.  
  7. tableView = QtGui.QTableView()
  8. tableView.setSortingEnabled (True)
  9. model = QtGui.QFileSystemModel()
  10.  
  11. tableView.setModel(model)
  12.  
  13. layout.addWidget(tableView)
  14.  
  15.  
  16. self.setLayout(layout)
  17.  
  18. dir = QtCore.QDir('/user/bobby')
  19. root = model.setRootPath(dir.path())
  20. files = dir.entryList()
  21. tableView.setRootIndex(root)
To copy to clipboard, switch view to plain text mode