void ResourceTreeDelegate
::paint(QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
int column = index.column();
if (column == ResourceTreeModel::Progress) {
painter->save();
if (index.data().isNull()) {
QStyledItemDelegate::paint(painter, option, index);
}
else {
QColor backgroundColor
= qvariant_cast<QColor>
(index.
data(Qt
::BackgroundColorRole));
int value = index.data().toInt();
if (value < 0) value = 0;
int x = option.rect.x();
int y = option.rect.y();
int width = option.rect.width();
int height = option.rect.height();
// make with margins
int margin = ResourceTreeDelegateConstants::PROGRESS_BAR_MARGIN;
int progressBarHeight = ResourceTreeDelegateConstants::PROGRESS_BAR_HEIGHT;
QRect newRect
(x
+ margin,
y + (int)(height / 2.0) - 7,
width - (2 * margin),
progressBarHeight);
progressBarOption.
palette.
setColor(QPalette::Window, backgroundColor
);
progressBarOption.
palette.
setColor(QPalette::Highlight, highlightColor
);
progressBarOption.rect = newRect;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = value;
progressBarOption.
text = QString(" %1%").
arg(QString::number(value
)).
leftJustified(7,
' ');
progressBarOption.textVisible = true;
painter->fillRect(option.rect, progressBarOption.palette.background());
&progressBarOption, painter);
}
if (index.isValid()) {
painter->setPen(Qt::lightGray);
painter->drawRect(option.rect);
}
painter->restore();
}
QStyledItemDelegate::paint(painter, option, index);
}
void ResourceTreeDelegate::paint(QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
int column = index.column();
if (column == ResourceTreeModel::Progress) {
painter->save();
if (index.data().isNull()) {
QStyledItemDelegate::paint(painter, option, index);
}
else {
QColor backgroundColor = qvariant_cast<QColor>(index.data(Qt::BackgroundColorRole));
QColor highlightColor = option.palette.color(QPalette::Highlight);
int value = index.data().toInt();
if (value < 0) value = 0;
int x = option.rect.x();
int y = option.rect.y();
int width = option.rect.width();
int height = option.rect.height();
// make with margins
int margin = ResourceTreeDelegateConstants::PROGRESS_BAR_MARGIN;
int progressBarHeight = ResourceTreeDelegateConstants::PROGRESS_BAR_HEIGHT;
QRect newRect(x + margin,
y + (int)(height / 2.0) - 7,
width - (2 * margin),
progressBarHeight);
QStyleOptionProgressBar progressBarOption;
progressBarOption.palette.setColor(QPalette::Window, backgroundColor);
progressBarOption.palette.setColor(QPalette::Highlight, highlightColor);
progressBarOption.rect = newRect;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = value;
progressBarOption.text = QString(" %1%").arg(QString::number(value)).leftJustified(7, ' ');
progressBarOption.textVisible = true;
painter->fillRect(option.rect, progressBarOption.palette.background());
QApplication::style()->drawControl(QStyle::CE_ProgressBar,
&progressBarOption, painter);
}
if (index.isValid()) {
painter->setPen(Qt::lightGray);
painter->drawRect(option.rect);
}
painter->restore();
}
QStyledItemDelegate::paint(painter, option, index);
}
To copy to clipboard, switch view to plain text mode
Bookmarks