Ok, I'm trying the following snippet but it doesn't seem to work (I receive Segmentation Fault):
{
if(idx.column() == 5)
{
if(!QFile::exists(idx.
data().
toString())) imgFile = ":/centinela/images/picture_unavailable.jpg";
QPixmap pixmap
(idx.
data().
toString());
if(role == Qt::DecorationRole)
return pixmap;
if(role == Qt::SizeHintRole)
return pixmap.size();
}
}
QVariant PersonasModel::data(const QModelIndex &idx, int role) const
{
if(idx.column() == 5)
{
if(!QFile::exists(idx.data().toString()))
imgFile = ":/centinela/images/picture_unavailable.jpg";
QPixmap pixmap(idx.data().toString());
if(role == Qt::DecorationRole)
return pixmap;
if(role == Qt::SizeHintRole)
return pixmap.size();
return QSqlTableModel::data(idx, role);
}
return QSqlTableModel::data(idx, role);
}
To copy to clipboard, switch view to plain text mode
If instead, I try the following, it does work, but I can't provide the SizeHint:
{
if(idx.column() == 5 && role == Qt::DecorationRole)
{
return QPixmap(idx.
data().
toString());
}
}
QVariant PersonasModel::data(const QModelIndex &idx, int role) const
{
if(idx.column() == 5 && role == Qt::DecorationRole)
{
return QPixmap(idx.data().toString());
}
return QSqlTableModel::data(idx, role);
}
To copy to clipboard, switch view to plain text mode
Note that the fifth column of my model is the one storing the pictures. And I would like to be able to render a default picture, in case one is not available.
Bookmarks