I write it as height
scalable :
QLabel lbl;
int count = 0;
QString str = "";
// set lbl text
lbl.setText("hfdsf\ncsad\nfsc\dajkjkjkjhhkdkca\n925");
str = lbl.text();
for(int i = 0;i < str.length();i++)
if(str.at(i).cell() == '\n')
count++;
// resize lbl (width and height)
lbl.resize(lbl.fontMetrics().width("this is the max-length line in qlabel")
, lbl.fontMetrics().height() * (count + 1));
Notice : this work if you change QLable
font face
or size
! just in height scalable (before every thing set your QLabel
frameShape to BOX
).
if you want do width
scalable-content, you should do these steps :
- read
QLabel
(lbl object
) text as line to line
- calculate every line length
- select maximum of line length
- use of
QLabel::fontMetrics().width(QString str)
for investigate str
size in width
I hope this can help you...