Solved Text.Fit ,WrapMode and MaximumLineCount
-
Hi,
I wanted to Fit a Text within 2 lines and I have provided the wrap mode as Text.Wrap. and maxlineCount as 2.
Ex:
Text {
width:30
height:30
fontSize:12
maximumLineCount: 2
fontSizeMode: Text.Fit
font.pixelSize:12
wrapMode: Text.Wrap
minimumPixelSize: -1
text: "ABCD EFGH IJKL"
}
The output which i recieve is only :
ABCD
EFGH.I Require the entire string to be displayed .
The Text Wraps into 2 lines, but the entire text is not fit.
Am i missing some property which i would require to be set? -
If the text does not fit, you need to either set the elide property or if you don't want that, you need to make the text wider so that it fits properly (modify
width
). -
@sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:
Hi Sierdzio,
The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?
-
@Anita said in Text.Fit ,WrapMode and MaximumLineCount:
@sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:
Hi Sierdzio,
The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?
Yes, although it's not straightforward. You need to use FontMetrics or TextMetrics to figure out a proper text size which will fit the space you have available.
-
@sierdzio
Hi,I could not use the fontMetrics/TextMetrics.
I tried using :
Text{
id:twolinetxt
width:30
height: 30
text: "ABCD EFGH IJKL"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
// maximumLineCount: 1
fontSizeMode: Text.Fit
font.pixelSize:12
lineHeight:(twolinetxt.height/2).toFixed(0)
lineHeightMode:Text.FixedHeight
wrapMode: Text.WordWrap
minimumPixelSize: 1
}where 2 in the line lineHeight:(twolinetxt.height/2).toFixed(0) specifies max line count.
It has worked.
Thank You :) .