Hola,
spent whole night trying to figure out this problem. No luck.

I'm using a QSqlRelationalTableModel-derived class to handle a database table with a QTableView. However, I have to insert one custom column to the model for displaying additional info.

In app's constructor:

Qt Code:
  1. static CMyTableModel model; // Derived from QSqlRelationalTableModel
  2. model.setTable("BookTable"); // 2 fields: ID and Name
  3. model.select(); // Populate from database
  4. model.insertColumn(2); // Insert column for additional data
To copy to clipboard, switch view to plain text mode 

I set up the QTableView:

Qt Code:
  1. QTableView* tv = ui.tableview;
  2. tv->setModel(&model); // Set model
  3. tv->hideColumn(0); // Hide ID
  4. tv->setItemDelegateForColumn(2, new CMyDelegate()); // Set our delegate to custom column
  5. tv->setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::DoubleClicked);
To copy to clipboard, switch view to plain text mode 

I have overriden data to handle the additional column:

Qt Code:
  1. QVariant CMyTableModel::data(const QModelIndex &item, int role) const
  2. {
  3. if(item.column() == 2) // Our column
  4. {
  5. if(role == Qt::DisplayRole)
  6. {
  7. return QString(...);
  8. }
  9.  
  10. if(role == Qt::EditRole)
  11. {
  12. return QString(...);
  13. }
  14. }
  15.  
  16. // Default
  17. return QSqlRelationalTableModel::data(item, role);
  18. }
To copy to clipboard, switch view to plain text mode 

And here's the delegate's most important methods:

Qt Code:
  1. void CMyDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
  2. {
  3. // !!! PAINTS JUST FINE
  4. }
  5.  
  6. QWidget * CMyDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
  7. {
  8. return new QPushButton("test"); // !!! NEVER CALLED
  9. }
To copy to clipboard, switch view to plain text mode 

Whatever I try, I just can't get the inserted column to enter edit mode. What's missing? Would REALLY appreciate some help here. Thanks.