That seemed to work, until I went past the first row. Made a small change and it all seems to be working as intended now, just need to check different sized images and figure out why a relative path is not working.
{
QString header
= model
->headerData
(index.
column(),
Qt::Horizontal).toString();
if(header == "Image")
{
QString link
= index.
data().
toString();
pixmap = pixmap.scaled(option.rect.size(), Qt::KeepAspectRatio);
int centerCell = option.rect.width() / 2;
int centerPixmap = pixmap.width() / 2;
painter->drawPixmap(centerCell - centerPixmap, option.rect.y(),
pixmap);
}
else
QStyledItemDelegate::paint(painter, option, index);
}
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QString header = model->headerData(index.column(),
Qt::Horizontal).toString();
if(header == "Image")
{
QString link = index.data().toString();
QPixmap pixmap(link);
pixmap = pixmap.scaled(option.rect.size(), Qt::KeepAspectRatio);
int centerCell = option.rect.width() / 2;
int centerPixmap = pixmap.width() / 2;
painter->drawPixmap(centerCell - centerPixmap, option.rect.y(),
pixmap);
}
else
QStyledItemDelegate::paint(painter, option, index);
}
To copy to clipboard, switch view to plain text mode
Thanks all.
Bookmarks