у меня есть пример делегата кот. отображает картинку если в ячейке содержится путь к ней (имя файла ), если чуть переделаете подойдет и вам
C++ (Qt)
class CPictureDelegate : public QItemDelegate
{
mutable QPixmap m_pxPicture;
public:
CPictureDelegate( QObject *parent );
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
//QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
C++ (Qt)
CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent)
{
}
void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
m_pxPicture.fill( QColor(Qt::white) );
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
if ( !sFileName.isEmpty() )
m_pxPicture.load( sFileName );
//QItemDelegate::paint(painter, option, index);
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
QPalette::Disabled;
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
painter->drawPixmap( nX, nY, m_pxPicture );
drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
/*
QPen pen = painter->pen();
painter->setPen(option.palette.color(QPalette::Mid));
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->setPen(pen);
*/
}