Fix file names overflowing after text eliding (take 2)

!992 (merged) re-introduced the usage of QFontMetrics::boundingRect(QString) for calculating the size of the last line of a filename. ..Unfortunately, that function uses a different code path from QTextLayout, and arrives at a shorter width for a line of text.

Meanwhile, QFontMetrics::size(QString) internally uses QFontMetric::boundingRect(QRect, int, QString, ..), which has been documented as "The bounding rectangle returned by this function is somewhat larger than that calculated by the simpler boundingRect() function. This function uses the maximum left and right font bearings as is necessary for multi-line text to align correctly."

I have empirically confirmed that QFontMetricsF::size and QTextLine::naturalTextWidth return the same floating-point value given the same input, meaning there's a good chance those two use the same code path. Hopefully. I think.

Is there any good internal Qt documentation on all the intricacies of text rendering? The cat-and-mouse game with text layouting issues is rather inefficient 😂

BUG: 432530


Old: image

New: image

Edited by Méven Car

Merge request reports

Loading