short answer: QFilterSortProxyModel cant work using a proxy model.
long answer: need to subclass QSqlRelationalDelegate to search in the proxy mode, the source model. and call the base function using the model and index if the sourceModel()
1- need to find the first not-proxy model using the 'index', and the mapped model index related to proxy index 'index' and return the source model index and the index mapped from the proxy model
std
::tuple<QAbstractItemModel
*, QModelIndex> findSourceModel
(QModelIndex index
) const{
while( source_model->inherits("QAbstractProxyModel") ){
//qDebug() << "class name from proxy model " << source_model->metaObject()->className();
source_index = static_cast<QAbstractProxyModel *>(source_model)->mapToSource(source_index);
source_model = static_cast<QAbstractProxyModel *>(source_model)->sourceModel();
}
return {source_model, source_index};
}
std::tuple<QAbstractItemModel *, QModelIndex> findSourceModel(QModelIndex index) const
{
QAbstractItemModel * source_model = (QAbstractItemModel *)index.model();
QModelIndex source_index = index;
while( source_model->inherits("QAbstractProxyModel") ){
//qDebug() << "class name from proxy model " << source_model->metaObject()->className();
source_index = static_cast<QAbstractProxyModel *>(source_model)->mapToSource(source_index);
source_model = static_cast<QAbstractProxyModel *>(source_model)->sourceModel();
}
return {source_model, source_index};
}
To copy to clipboard, switch view to plain text mode
and use the returned values whit the base class implementation of QSqlRelationalDelegate
{
auto[source_model, source_index] = findSourceModel(index);
}
QWidget *QSqlRelationalProxyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
auto[source_model, source_index] = findSourceModel(index);
return QSqlRelationalDelegate::createEditor(parent,option,source_index);
}
To copy to clipboard, switch view to plain text mode
NOTE:
for a not proxy model. i refer to any subclass of QAbstractProxyModel, mainly a QSortProxyModelor QIdentityProxyModelsubclass
I apologize for responding with a code in C++, but I haven't programmed in Python for a long time, it should be easy to convert it to Python.
I hope it is useful to you
Bookmarks