Hi,

I want to use the QSortFilterProxyModel on my custom model for sorting/filtering purpose. But when applying it, the list in my TableView is empty.

If I do not use my custom model, but the QStandardItemModel (as in the examples "basic sort/filter model"), it works.

So it seems my custom model is at fault here, although it works just fine if I do not use the QSortFilterProxyModel.
Does my custom model require additional method implementations for it to work?
Or do I have subclass the QSortFilterProxyModel? If so, what would I need to change?

Here is my custom model:
Qt Code:
  1. class MyTableModel(QAbstractTableModel):
  2. def __init__(self, datain, parent=None, *args):
  3. QAbstractTableModel.__init__(self, parent, *args)
  4. self.arraydata = datain
  5.  
  6. def rowCount(self, parent):
  7. return len(self.arraydata)
  8.  
  9. def columnCount(self, parent):
  10. return len(self.arraydata[0])
  11.  
  12. def data(self, index, role):
  13. if not index.isValid():
  14. return QVariant()
  15. elif role != Qt.DisplayRole:
  16. return QVariant()
  17. return QVariant(self.arraydata[index.row()][index.column()])
To copy to clipboard, switch view to plain text mode