From a920e8d55db46aeec4e3a5800c46a19c8ba4b14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Martsum?= Date: Fri, 31 May 2013 06:40:44 +0200 Subject: [PATCH] QTableView::sizeHintForRow minor fix of word wrap in a special case In case we do a resizeSection to 0 (can also happen by a reset) then the auto resize won't work with word wrap. The first resize afterwards it will only resize to a single line. Change-Id: I3abf779ecb0593b6721f5af16f7a39d05004e98f Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qtableview.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 990e07bfcb..d282397c1b 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -965,7 +965,16 @@ int QTableViewPrivate::heightHintForIndex(const QModelIndex &index, int hint, QS if (wrapItemText) {// for wrapping boundaries option.rect.setY(q->rowViewportPosition(index.row())); - option.rect.setHeight(q->rowHeight(index.row())); + int height = q->rowHeight(index.row()); + // if the option.height == 0 then q->itemDelegate(index)->sizeHint(option, index) will be wrong. + // The option.height == 0 is used to conclude that the text is not wrapped, and hence it will + // (exactly like widthHintForIndex) return a QSize with a long width (that we don't use) - + // and the height of the text if it was/is on one line. + // What we want is a height hint for the current width (and we know that this section is not hidden) + // Therefore we catch this special situation with: + if (height == 0) + height = 1; + option.rect.setHeight(height); option.rect.setX(q->columnViewportPosition(index.column())); option.rect.setWidth(q->columnWidth(index.column())); }