This is the code I ended up with (from the QSqlRelationalDelegate 's code), and works!
Any comments are welcome.
Qt Code:
  1. int positionColumn = 2;
  2. qDebug()<< "BookDelegate.createEditor index.column()=" << (index.column()) << " option=" << option ;
  3. if (index.column() == positionColumn){
  4. const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
  5. QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : nullptr;
  6. if (!childModel)
  7. return QStyledItemDelegate::createEditor(parent, option, index);
  8.  
  9. QComboBox *combo = new QComboBox(parent);
  10. combo->setModel(childModel);
  11. combo->setModelColumn(1);
  12. combo->installEventFilter(const_cast<BookDelegate *>(this));
  13. childModel->select();
  14. return combo;
  15. }
To copy to clipboard, switch view to plain text mode