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:
def __init__(self, datain, parent=None, *args):
self.arraydata = datain
def rowCount(self, parent):
return len(self.arraydata)
def columnCount(self, parent):
return len(self.arraydata[0])
def data(self, index, role):
if not index.isValid():
elif role != Qt.DisplayRole:
return QVariant(self.
arraydata[index.
row()][index.
column()])
class MyTableModel(QAbstractTableModel):
def __init__(self, datain, parent=None, *args):
QAbstractTableModel.__init__(self, parent, *args)
self.arraydata = datain
def rowCount(self, parent):
return len(self.arraydata)
def columnCount(self, parent):
return len(self.arraydata[0])
def data(self, index, role):
if not index.isValid():
return QVariant()
elif role != Qt.DisplayRole:
return QVariant()
return QVariant(self.arraydata[index.row()][index.column()])
To copy to clipboard, switch view to plain text mode
Bookmarks