Re: Dynamically resize text
Just a quick simple suggestion, perhaps try fiddling with font.pixelSize instead.
Code:
property int fontSize: Math.round(textButton.height / 4)
...
font.pixelSize: (invisibleText.paintedWidth > parent.width) ? (parent.width / invisibleText.paintedWidth) * fontSize : fontSize
Re: Dynamically resize text
That works, too. I have not found any difference in the behavior of font.pixelsize and font.pointsize in this case.
However, I was hoping to get rid of the 'invisible text'-hack somehow.
Re: Dynamically resize text
I found that using pixelSize avoided this problem...
Quote:
the text sometimes jumps in size and can, under specific circumstances, still exceed the rectangle length
Re: Dynamically resize text
Quote:
Originally Posted by
antialias_forum
However, I was hoping to get rid of the 'invisible text'-hack somehow.
You could scale the Text based on how much it exceeds your width at the specified pixelSize:
Code:
import Qt 4.7
Rectangle {
width: 200
height: 200
Text {
width: 200
height: 100
text: "Some sample text here"
font.pixelSize: height / 4
scale: paintedWidth > width ? (width / paintedWidth) : 1
transformOrigin: Item.TopLeft
}
}