So my final solution is:
class SqlRelationalDelegate : public QSqlRelationalDelegate {
Q_OBJECT
public:
StorageSqlRelationalDelegate(QObject* parent = nullptr) : QSqlRelationalDelegate(parent) {}
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override {
editor = QSqlRelationalDelegate::createEditor(parent, option, index);
return editor;
}
void destroyEditor(QWidget* editor, const QModelIndex& index) const override {
QSqlRelationalDelegate::destroyEditor(editor, index);
this->editor = nullptr;
}
QWidget* getEditor() const {
return editor;
}
private:
mutable QWidget* editor = nullptr;
};
...
class TableView : public QTableView {
Q_OBJECT
public:
StorageTableView(QWidget* parent = nullptr) {}
void openPersistentEditor(const QModelIndex &index) {
QTableView::openPersistentEditor(index);
emit persistentEditorOpened(index);
}
signals:
void persistentEditorOpened(const QModelIndex &index);
};
...
connect(view, &TableView::persistentEditorOpened, [view] (const QModelIndex& index) {
auto model = view->model();
auto delegate = qobject_cast<SqlRelationalDelegate*>(view->itemDelegate(index));
if (!delegate)
qFatal("Delegate cast error");
delegate->setModelData(delegate->getEditor(), model, index);
});