I have a QSqlTableModel, a QTableView and a QStyledItemDelegate.

I can find out the column name in paint() this way:
Qt Code:
  1. QString fieldname, tablename;
  2. const QAbstractItemModel *abstractmodel = index.model();
  3.  
  4. if( abstractmodel->inherits( "QSqlQueryModel"))
  5. {
  6. QSqlQueryModel *model = (QSqlQueryModel *)abstractmodel;
  7. QSqlRecord rec = model->record();
  8. fieldname = rec.fieldName(col);
  9. }
To copy to clipboard, switch view to plain text mode 

Same if I use QSqlTableModel instead of for QSqlQueryModel. This part works.

But now I need to find out the tablename because when I use QSqlQueryModel I can join multiple tables and I can't identify a certain column only by the column name, I also need the table name...