From ef60435d2f5bc1f3962388a3b51941015893a4d0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 13 Jan 2018 13:54:31 +0100 Subject: QCommonStylePrivate::viewItemSize: fix text height calculation QCommonStylePrivate::viewItemSize did not adjust the width when the item had a decoration or a checkbox. This lead to a too big width used for the layouting and therefore sometimes the calculated height was too small. Task-number: QTBUG-30116 Change-Id: I4468daa9820b9a8aa00fe959ab9b73fec23cc24e Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qtableview.cpp | 3 +++ src/widgets/styles/qcommonstyle.cpp | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 1e6a60a4d7..ec25ccdb12 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -971,6 +971,9 @@ int QTableViewPrivate::heightHintForIndex(const QModelIndex &index, int hint, QS option.rect.setHeight(height); option.rect.setX(q->columnViewportPosition(index.column())); option.rect.setWidth(q->columnWidth(index.column())); + // 1px less space when grid is shown (see drawCell) + if (showGrid) + option.rect.setWidth(option.rect.width() - 1); } hint = qMax(hint, q->itemDelegate(index)->sizeHint(option, index).height()); return hint; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 9f51a6b9d6..4a83cdd4a6 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -889,6 +889,13 @@ 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); + } + const int lineWidth = bounds.width(); const QSizeF size = viewItemTextLayout(textLayout, lineWidth); return QSize(qCeil(size.width()) + 2 * textMargin, qCeil(size.height())); -- cgit v1.2.3