From db738cbaf1ba7a4886f7869db16dbb9107a8e65e Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Thu, 12 Jul 2018 10:55:33 +0200 Subject: QCommonStylePrivate::viewItemSize: Fix text width bounds calculation The width of the icon was subtracted out of the available text area width even when the value of the `decorationPosition` was Top/Bottom. Task-number: QTBUG-69404 Task-number: QTBUG-30116 Change-Id: I501ffc0dab0cff25e525c26adf9bdb060408927b Reviewed-by: Christian Ehrlicher Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 7420bfb3f7..3b9186e61a 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -879,9 +879,16 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int QRect bounds = option->rect; switch (option->decorationPosition) { case QStyleOptionViewItem::Left: - case QStyleOptionViewItem::Right: - bounds.setWidth(wrapText && bounds.isValid() ? bounds.width() - 2 * textMargin : QFIXED_MAX); + case QStyleOptionViewItem::Right: { + if (wrapText && bounds.isValid()) { + int width = bounds.width() - 2 * textMargin; + if (option->features & QStyleOptionViewItem::HasDecoration) + width -= option->decorationSize.width() + 2 * textMargin; + bounds.setWidth(width); + } else + bounds.setWidth(QFIXED_MAX); break; + } case QStyleOptionViewItem::Top: case QStyleOptionViewItem::Bottom: if (wrapText) @@ -893,12 +900,8 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int break; } - if (wrapText) { - if (option->features & QStyleOptionViewItem::HasCheckIndicator) - bounds.setWidth(bounds.width() - proxyStyle->pixelMetric(QStyle::PM_IndicatorWidth) - 2 * textMargin); - if (option->features & QStyleOptionViewItem::HasDecoration) - bounds.setWidth(bounds.width() - option->decorationSize.width() - 2 * textMargin); - } + if (wrapText && option->features & QStyleOptionViewItem::HasCheckIndicator) + bounds.setWidth(bounds.width() - proxyStyle->pixelMetric(QStyle::PM_IndicatorWidth) - 2 * textMargin); const int lineWidth = bounds.width(); const QSizeF size = viewItemTextLayout(textLayout, lineWidth); -- cgit v1.2.3