From b39acbf9542bcce929a48070e3f6123eaa74078d Mon Sep 17 00:00:00 2001 From: Pan Zhang Date: Fri, 21 Nov 2025 11:19:27 +0800 Subject: kstandarditemlistwidget: Fix vertical misalignment for file names containing certain glyphs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the Details view the name (text) column could appear vertically off-center for file names containing certain Unicode glyphs (for example "』"). The issue is caused by a mismatch between the generic font metrics ascent and the actual ascent of the rendered QTextLine for that glyph, which shifts the baseline and thus the visual vertical centering. This change computes the QTextLine ascent for the (single) layouted line and adjusts the vertical position by the difference between the font metrics ascent and the line ascent. The adjustment is applied only for the name (text) role so other columns are unaffected. BUG: 512152 --- src/kitemviews/kstandarditemlistwidget.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index a26b8dfcd..f197644c6 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -1481,7 +1481,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() } qreal x = firstColumnInc; - const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2); + const qreal standardY = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2.0); for (const QByteArray &role : std::as_const(m_sortedVisibleRoles)) { QString text = roleText(role, values); @@ -1508,6 +1508,16 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() TextInfo *textInfo = m_textInfo.value(role); textInfo->staticText.setText(text); + qreal y = standardY; + if (isTextRole) { + QTextLayout layout(text, m_customizedFont); + layout.beginLayout(); + QTextLine line = layout.createLine(); + layout.endLayout(); + if (line.isValid()) { + y = standardY + (m_customizedFontMetrics.ascent() - line.ascent()); + } + } textInfo->pos = QPointF(isLeftToRight ? (x + columnWidthInc / 2) : (size().width() - (x + columnWidthInc / 2) - requiredWidth), y); x += roleWidth; -- cgit v1.3