Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make reduce/expand QLabel according to text

Tags:

qt

qlabel

Suppose I have a QLabel and want to change its text. If text is too long to be show entirely, I loose a part of it. Can I re-dimension the QLabel according to the text I write in it?

like image 590
LittleSaints Avatar asked Nov 29 '25 13:11

LittleSaints


1 Answers

If you put your label into a layout its size will change to fit the text it contains (in the limits of the available space given by the layout).

By default QLabel has a horizontal-sizePolicy of QSizePolicy::Preferred which makes it to resize just enough to display its content (or expand if there is empty space around that no other widget use, or reduce if others widgets are requiring too much space).

like image 181
ymoreau Avatar answered Dec 01 '25 08:12

ymoreau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!