your program crashes, because you should write
QString imgFile = QSqlTableModel::data(idx, Qt::DisplayRole);
To copy to clipboard, switch view to plain text mode
instead of
QString imgFile
= idx.
data().
toString();
QString imgFile = idx.data().toString();
To copy to clipboard, switch view to plain text mode
try to exactly repeat my previous code...
{
if ( idx.column() == 5 )
{
if ( Qt::DisplayRole == role )
{
}
if ( !QFile::exists( imgFile
) {
imgFile = ":/centinela/images/picture_unavailable.jpg";
}
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 )
{
QString imgFile = QSqlTableModel::data( idx, Qt::DisplayRole );
if ( Qt::DisplayRole == role )
{
return QString();
}
if ( !QFile::exists( imgFile )
{
imgFile = ":/centinela/images/picture_unavailable.jpg";
}
QPixmap pixmap( imgFile );
if ( role == Qt::DecorationRole )
{
return pixmap;
}
if(role == Qt::SizeHintRole)
{
return pixmap.size();
}
}
return QSqlTableModel::data( idx, role );
}
To copy to clipboard, switch view to plain text mode
should I call QTableView::resizeRowsToContents() ?
honestly, I don't know. try ...
Bookmarks