PDA

View Full Version : add Pixmap to QueryModel



janus
28th May 2008, 19:56
Hi,
I get a bool from the database and would like to display an image instead. But returning a Pixmap (or Icon) shows an empty cell. If i return the pic for the DecorationRole it is displayed. Any idea?
I have a subclass of QSqlQueryModel an the data() funktion looks like this:


QVariant SqlQueryModel::data(const QModelIndex & index, int role) const
{
QString curr(QSqlQueryModel::data(index, Qt::DisplayRole).toString());

if ( index.column() == 2 && role == Qt::DisplayRole ){

// return QVariant(QString("sometext")); // is displayed
return QVariant(QPixmap(":/somepic.png")); // is not displayed

}else{

return QSqlQueryModel::data(index, role);
}
}

wysota
28th May 2008, 20:09
DisplayRole is meant to hold text and text only. Icons are displayed using DecorationRole. If you want to change this behaviour, you'll have to provide your own item delegate or use a proxy model that will take the icon from DisplayRole and return it as DecorationRole.