QHeaderView: consider Qt::DecorationRole size within paintSection()

When an icon was given through Qt::DecorationRole, the available space
for the text was not adjusted which created a graphical glitch.

Task-number: QTBUG-62091
Change-Id: I0f20b6de95deed14fb882efde5c81b83ab3e9a7e
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Christian Ehrlicher 2018-01-12 20:33:53 +01:00
parent fd3f732489
commit 2950de715e

View File

@ -2848,14 +2848,18 @@ void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logical
if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex && isHeaderArrowOnTheSide)
margin += style()->pixelMetric(QStyle::PM_HeaderMarkSize, 0, this);
if (d->textElideMode != Qt::ElideNone)
opt.text = opt.fontMetrics.elidedText(opt.text, d->textElideMode , rect.width() - margin);
QVariant variant = d->model->headerData(logicalIndex, d->orientation,
const QVariant variant = d->model->headerData(logicalIndex, d->orientation,
Qt::DecorationRole);
opt.icon = qvariant_cast<QIcon>(variant);
if (opt.icon.isNull())
opt.icon = qvariant_cast<QPixmap>(variant);
if (!opt.icon.isNull()) // see CT_HeaderSection
margin += style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this) +
style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this);
if (d->textElideMode != Qt::ElideNone)
opt.text = opt.fontMetrics.elidedText(opt.text, d->textElideMode , rect.width() - margin);
QVariant foregroundBrush = d->model->headerData(logicalIndex, d->orientation,
Qt::ForegroundRole);
if (foregroundBrush.canConvert<QBrush>())