Solved How to adapt PixelSize if Text width is fixed
-
Hello,
I have trouble to do a simple thing.
I have a
Text Component
that cannot have awidth
bigger than 300 (this is an example).
I have a defaultfont.pixelSize
. However, if mytext
has too many characters, I would like to reduce thepixelSize
of it.Example:
Text { ont.pixelSize: 20 text : myText //If Text width > 300, I would like to change font.pixelSize }
Any suggestion ? Thanks a lot
-
Text { font.pixelSize: 20 * (width > 300 ? 300 / width : 1 ) }
but it causes property binding loop...
Howeverscale
could do the trick:Text { scale: width > 300 ? 300 / width : 1 }
-
See Text::fontSizeMode. There's
Text.HorizontalFit
. -
Thanks, this is what I need.
Have a good day