Solved fontsizemode
-
hi
I am trying to use fontsizemode because I have to make size of text small based on text lengthmy code:
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { color: "Red" height:50 width:50 Text { text: "Hello"; fontSizeMode: Text.Fit; minimumPixelSize: 5; font.pixelSize: 50 } } }
but it is not working is anything wrong in my program?
-
Solved this problem
working code:Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { color: "Red" height:50 width:50 Text { width:parent.width height: parent.height text: "Hello"; fontSizeMode: Text.Fit; minimumPixelSize: 5; font.pixelSize: 50 } } }
-
Hello,
If you want your text to be fitted in the Rectangle, just add the next line to your Text component:
anchors.fill: parent
Like this:
Text { anchors.fill: parent text: "Hello"; fontSizeMode: Text.Fit; minimumPixelSize: 5; font.pixelSize: 50 }
Now Text will have the same width and height as Rectangle. And using
fontSizeMode: Text.Fit
will fit both width and height of Rectangle. You can also useText.HorizontalFit
orText.VerticalFit
to fit in width or height. -
@krokstr Thank you.