diff options
| author | Emmanuel Pescosta <[email protected]> | 2014-08-04 19:43:07 +0200 |
|---|---|---|
| committer | Emmanuel Pescosta <[email protected]> | 2014-08-04 19:43:07 +0200 |
| commit | 18a976c435e85fa2556b1a1abb6de41392003d7d (patch) | |
| tree | ad3e9a8fcd92bfc66bd1e3b854dfd84e0d5535fc /src/kitemviews/kstandarditemlistwidget.cpp | |
| parent | a31b836479a1df2138fb4cc295db2f2a4fb97ed8 (diff) | |
Fix wrong text eliding in some corner cases.
BUG: 337104
FIXED-IN: 4.14.0
REVIEW: 119546
Diffstat (limited to 'src/kitemviews/kstandarditemlistwidget.cpp')
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index 998acc066..6407efc22 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1136,14 +1136,24 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() const int textLength = line.textStart() + line.textLength(); if (textLength < nameText.length()) { // Elide the last line of the text - QString lastTextLine = nameText.mid(line.textStart()); - lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine, - Qt::ElideRight, - maxWidth); - const QString elidedText = nameText.left(line.textStart()) + lastTextLine; - nameTextInfo->staticText.setText(elidedText); + qreal elidingWidth = maxWidth; + qreal lastLineWidth; + do { + QString lastTextLine = nameText.mid(line.textStart()); + lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine, + Qt::ElideRight, + elidingWidth); + const QString elidedText = nameText.left(line.textStart()) + lastTextLine; + nameTextInfo->staticText.setText(elidedText); + + lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width(); + + // We do the text eliding in a loop with decreasing width (1 px / iteration) + // to avoid problems related to different width calculation code paths + // within Qt. (see bug 337104) + elidingWidth -= 1.0; + } while (lastLineWidth > maxWidth); - const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width(); nameWidth = qMax(nameWidth, lastLineWidth); } break; |
