[Interest] [External] Proxied view not updating live when source model does
Murphy, Sean
Sean.Murphy at centauricorp.com
Tue Sep 21 15:58:24 CEST 2021
> I'm having an issue where my proxy model and its associated view aren't
> updating live when changes are made in the source model.
>
> My proxy model simply is attempting to invert the rows of the source model. So
> it inherits from a QSortFilterProxyModel and implements mapFromSource() and
> mapToSource() as follows:
>
> QModelIndex invertRowsModel::mapFromSource(const QModelIndex
> &sourceIndex) const
> {
> if(sourceIndex.isValid() && rowCount() > 0)
> {
> return this->index(rowCount() - sourceIndex.row() - 1,
> sourceIndex.column());
> }
>
> return QModelIndex();
> }
>
Small update here, but I'm not sure what it actually means... I added a debug
statement at the top of my mapFromSource() function, so now that function reads like so:
QModelIndex invertRowsModel::mapFromSource(const QModelIndex &sourceIndex) const
{
if(sourceIndex.isValid() && rowCount() > 0)
{
qDebug() << __FUNCTION__ << "valid index" << sourceIndex;
return this->index(rowCount() - sourceIndex.row() - 1, sourceIndex.column());
} else {
qDebug() << __FUNCTION__ << "invalid index" << sourceIndex;
}
return QModelIndex();
}
With this in place, while modifying the data in the source view, I NEVER see the
mapFromSource() "valid index" debug message from the proxy model. Right after
setData() is called in the source model, I see a couple of these messages come out
and that's it:
invertRowsModel::mapFromSource invalid index QModelIndex(-1,-1,0x0,QObject(0x0))
I'm not sure exactly what that means or how to address it, but it is a new data point...
Sean
More information about the Interest
mailing list