summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2020-12-06 14:09:26 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2020-12-08 15:15:58 +0100
commit4d943846128118e1b9932a17ce6f977a0f4127a5 (patch)
treecec5948b2e9dc6ce5424fa1e7f73e99729af43e8 /src/widgets/itemviews
parent1051e23ce91a980c5e961b4dcb6d61997bc08050 (diff)
QHeaderView: respect the font role while calculating the elided text
The font role in the header view was not taken into account when the text for an item should be elided. This leads to a wrongly elided text esp. visible when the font size is different to the font of QHeaderView. Fix it by passing the elide mode to the style since only the style knows the used font (e.g. bold or not bold) and available rect. This is now in sync with CE_ItemViewItem where the eliding is also done by the style and not by the item view. [ChangeLog][QtWidgets][QHeaderView] QStyleOptionHeader got a new member textElideMode. Fixes: QTBUG-86426 Change-Id: If6914fe5aaa5d285e6da55d2129f9249d90da3d7 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index becf1e1a24..d6c9700ed3 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -2952,10 +2952,11 @@ void QHeaderView::initStyleOptionForIndex(QStyleOptionHeader *option, int logica
margin += style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this) +
style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this);
- 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 var = d->model->headerData(logicalIndex, d->orientation,
+ Qt::FontRole);
+ if (var.isValid() && var.canConvert<QFont>())
+ opt.fontMetrics = QFontMetrics(qvariant_cast<QFont>(var));
+ opt.textElideMode = d->textElideMode;
QVariant foregroundBrush = d->model->headerData(logicalIndex, d->orientation,
Qt::ForegroundRole);