I'm using a QSortFilterProxyModel to filter results from a QAbstractListModel. However, I'd like to return a first entry which is not present in the original model, that is, it's somehow artificial.
This is what I have so far:
class ActivedAccountModel(QSortFilterProxyModel):                                                                                                                                  
    def __init__(self, model, parent=None):
        super(ActiveAccountModel, self).__init__(parent)
        self.setSourceModel(model)
        self.setDynamicSortFilter(True)
    def data(self, index, role=Qt.DisplayRole):
        account_info = super(ActiveAccountModel, self).data(index, Qt.UserRole).toPyObject()
        if role == Qt.DisplayRole:
            return account_info.name
        elif role == Qt.UserRole:
            return account_info
        return None
    def filterAcceptsRow(self, source_row, source_parent):
        source_model = self.sourceModel()
        source_index = source_model.index(source_row, 0, source_parent)
        account_info = source_model.data(source_index, Qt.UserRole)
        return isinstance(account_info.account, Account) and account_info.account.enabled
This will return a list in the form of:
Account 1
Account 2
...
Id' like to return an extra element at the begining of the returned list f elements:
Extra Element
Account 1
Account 2
...
I tried to reimplement rowCount in order to return the real rowCount()+1, but somehow I'd need to shift all the items in order to return this artificial element at index 0, and I'm a bit lost there.
Any clue? I couldn't find any related code example so far... Thanks!