//***********************************************************************//
myTable::myTable(...)
{
...
QSqlCursor* cursor = new QSqlCursor ("staff");
setSqlCursor(cursor);
//I retrieve five columns, but this is the one I am interested in here
addColumn("id_staff", "Name");
.....
setSorting( true );
....
}
const QRect& cr, bool selected)
{
if( ! field )
return;
....
if ( field->name() == "id_staff" )
{
int id = field->value().toInt();
//using the id_staff, I retrieve the name of the staff member in table "personnel"
p->drawText( 2, 2, cr.width() - 4, cr.height() - 4, Qt::AlignLeft, name);
}
}
//***********************************************************************//
//***********************************************************************//
myTable::myTable(...)
{
...
QSqlCursor* cursor = new QSqlCursor ("staff");
setSqlCursor(cursor);
//I retrieve five columns, but this is the one I am interested in here
addColumn("id_staff", "Name");
.....
setSorting( true );
....
}
myTable::paintField(QPainter *p, const QSqlField *field,
const QRect& cr, bool selected)
{
if( ! field )
return;
....
if ( field->name() == "id_staff" )
{
int id = field->value().toInt();
//using the id_staff, I retrieve the name of the staff member in table "personnel"
QString name = retrieveName(id);
p->drawText( 2, 2, cr.width() - 4, cr.height() - 4, Qt::AlignLeft, name);
}
}
//***********************************************************************//
To copy to clipboard, switch view to plain text mode
Bookmarks