QHeaderView: Take padding/margin into account when eliding text
When QHeaderView has an elide mode set, the available width passed to QFontMetrics::elidedText() was not adjusted when padding or margin was set. This lead to a too long text displayed in the header. Now QStyle::subElementRect(SE_HeaderLabel) is used to get the correct rect. Task-number: QTBUG-23203 Change-Id: I12fc646092470272bb91b3ffb7c7a51e239c7a35 Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
550d2a0a15
commit
fbd21e1024
@ -2968,8 +2968,10 @@ void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logical
|
||||
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);
|
||||
if (d->textElideMode != Qt::ElideNone) {
|
||||
const QRect textRect = style()->subElementRect(QStyle::SE_HeaderLabel, &opt, this);
|
||||
opt.text = opt.fontMetrics.elidedText(opt.text, d->textElideMode, textRect.width() - margin);
|
||||
}
|
||||
|
||||
QVariant foregroundBrush = d->model->headerData(logicalIndex, d->orientation,
|
||||
Qt::ForegroundRole);
|
||||
|
Loading…
Reference in New Issue
Block a user