PDA

View Full Version : Find out tablename in QStyledItemDelegate/QSqlQueryModel



Walter
1st August 2009, 17:39
I have a QSqlTableModel, a QTableView and a QStyledItemDelegate.

I can find out the column name in paint() this way:


QString fieldname, tablename;
const QAbstractItemModel *abstractmodel = index.model();

if( abstractmodel->inherits( "QSqlQueryModel"))
{
QSqlQueryModel *model = (QSqlQueryModel *)abstractmodel;
QSqlRecord rec = model->record();
fieldname = rec.fieldName(col);
}


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...