Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QLabel: interlinea/linespacing in WordWrap mode

Tags:

qt

qt4

How do I set line height in QLabel when in WordWrap mode?

like image 780
Regof Avatar asked May 01 '10 10:05

Regof


2 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 like 60 - 80. You will get condensed lines in the WordWrap mode

like image 129
lotekB Avatar answered Sep 19 '22 16:09

lotekB


There is no line spacing property in QLabel. You can change the widget font, which will change the line's height, but I suspect that is not what you want.

Line height is computed from the QFont of the widget and can be obtained by the QFontMetrics associated with the widget. Using this information, you may create your own widget that has a line spacing property (and a text wrap mode), but that represents a lot of low-level work.

like image 44
Lohrun Avatar answered Sep 20 '22 16:09

Lohrun