scaledPreview = imagePreview->scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation);lw->setData(Qt::UserRole+1, QVariant(scaledPreview));
QByteArray ba = index.data(Qt::UserRole+1).toByteArray(); QBuffer buffer(&ba); buffer.open(QIODevice::ReadWrite | QIODevice::Unbuffered); QImage *imagePreview = new QImage(); imagePreview->load(&buffer, "PNG"); QRect rect(QPoint(0,0), imagePreview->size()); painter->drawImage(rect, *imagePreview);
lw->setData(Qt::DecorateRole, QVariant(scaledPreview));
lw->setData(Qt::UserRole+1, QVariant("TEST"));
QString text = index.data(Qt::UserRole+1).toString(); painter->drawText(myOption.rect, Qt::AlignCenter, text);
void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ Q_ASSERT(index.isValid()); QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); ...}
void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ Q_ASSERT(index.isValid()); QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index);}
void PreviewTemplateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{QStyleOptionViewItemV4 myOption = option;initStyleOption(&myOption, index);myOption.displayAlignment = Qt::AlignLeft | Qt::AlignBottom;QString text = index.data(Qt::UserRole+1).toString();painter->drawText(myOption.rect, Qt::AlignCenter, text);}
QBrush ( const QPixmap & pixmap )QBrush ( const QImage & image )
void PreviewTemplateDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ Q_ASSERT(index.isValid()); QBrush brush = index.data(Qt::BackgroundRole).value<QBrush>(); QImage imagePreview = brush.textureImage(); painter->drawImage(QPoint(0,0), imagePreview); QStyledItemDelegate::paint(painter, option, index);}
QBrush background(scaledPreview);lw->setData(Qt::BackgroundRole, QVariant(background));
QSize PreviewTemplateDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{ Q_ASSERT(index.isValid()); QBrush brush = index.data(Qt::BackgroundRole).value<QBrush>(); QImage imagePreview = brush.textureImage(); QSize s = imagePreview.size(); return s;}