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 <ch.ehrlicher@gmx.de>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Ales Erjavec 2018-07-12 10:55:33 +02:00 committed by Aleš Erjavec
parent 780dc2291b
commit db738cbaf1

View File

@ -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);