void DownloadItemDelegate::paint(
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
painter->drawText(option.rect.x() + 2, option.rect.y() + option.fontMetrics.height(), index.data(Qt::DisplayRole).toString());
sop.
state = QStyle::State_Enabled;
sop.rect = option.rect.adjusted(2, option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height() + option.fontMetrics.height() / 2, -2, 0);
sop.fontMetrics = option.fontMetrics;
sop.minimum = 0;
sop.maximum = 100;
sop.progress = 50;
sop.orientation = Qt::Horizontal;
sop.textVisible = false;
}
QSize DownloadItemDelegate
::sizeHint(const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (option.
rect.
width() == 0 || option.
rect.
height() == 0) return QSize();
QSize size
= option.
rect.
size();
size.setHeight(option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height());
size.setHeight(size.height() + 20);
qDebug() << size.width() << "x" << size.height();
return size;
}
void DownloadItemDelegate::paint(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
painter->drawText(option.rect.x() + 2, option.rect.y() + option.fontMetrics.height(), index.data(Qt::DisplayRole).toString());
QStyleOptionProgressBarV2 sop;
sop.state = QStyle::State_Enabled;
sop.rect = option.rect.adjusted(2, option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height() + option.fontMetrics.height() / 2, -2, 0);
sop.fontMetrics = option.fontMetrics;
sop.minimum = 0;
sop.maximum = 100;
sop.progress = 50;
sop.orientation = Qt::Horizontal;
sop.textVisible = false;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &sop, painter);
}
QSize DownloadItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (option.rect.width() == 0 || option.rect.height() == 0) return QSize();
QSize size = option.rect.size();
size.setHeight(option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height());
size.setHeight(size.height() + 20);
qDebug() << size.width() << "x" << size.height();
return size;
}
To copy to clipboard, switch view to plain text mode
Bookmarks