summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-08-31 21:46:35 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-09-06 12:18:56 +0000
commitfbd21e1024d503b4b8b5e38b629a3b17392dbb05 (patch)
tree87c0e64a034a860e6a7119e720fc13caed360428 /src
parent550d2a0a15c9403894448ab83863e71bbac2d349 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index 6857ccd8bb..3396a91dc5 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -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);