Question

Is it just QFontMetrics::height(), or is it QFontMetrics::height()+QFontMetrics::leading()?

For example, in this code:

painter.drawText(QRect(x, y, 1000, 1000), "line1");
y += lineOffset;
painter.drawText(QRect(x, y, 1000, 1000), "line2");
y += lineOffset;
painter.drawText(QRect(x, y, 1000, 1000), "line3");

What would the value of lineOffset need to be in order for the lines to be spaced as if this code had been used:

painter.drawText(QRect(x, y, 1000, 1000), "line1\nline2\nline3");
Was it helpful?

Solution

As the documentation tells you, lineSpacing() is the vertical distance between two lines, and it is the sum of height() (the height of the font) and leading().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top