QLabel: interlinea / linespacing in WordWrap mode

How to set line height in QLabel in WordWrap mode?

+3
source share
3 answers

Use HTML text:

QString template = "<p style=\"line-height:%1%\">%2<p>";
QString targetText = template.arg(myPercentage).arg(myTex);
QLabel *l = new QLabel(targetText, this);

where myPercentage is similar to 60 - 80. You will get compressed lines in WordWrap mode

+4
source

There is QLabelno line spacing property. You can change the font of the widget, which will change the height of the line, but I suspect that this is not what you want.

QFont QFontMetrics, . , , ( ), .

+3

HTML QLabel Qt Designer.

  • Qt Designer.
  • QLabel text ....
  • "" HTML.

, QLabel HTML ( Qt 5.7). , ( ) HTML-, .

1

<html><head/><body>
<p style="line-height:120"><span>
This is the first line of the label.<br>
This is the second line.<br>
This is the third and final line.
</span></p>
</body></html>

, .

2

<html><head/><body>
<p style="line-height:20"><span>This is the first line of the label.</span></p>
<p style="line-height:20"><span>This is the second line.</span></p>
<p style="line-height:100"><span>This is the third and final line.</span></p>
</body></html>

In this example, you can control the spacing of each row individually. I had to make the height of the last line 100 so that Qt would not cut it in half. I assume this affects how Qt calculates the height of the label as a widget.

+1
source

Source: https://habr.com/ru/post/1743615/


All Articles