Hi all, I want to use the scale property of a Text so that the enclosed text shows up in its entirety (no wrap) within the size of the Text itself.
I’d like to be able to operate directly on the scale property instead of changing the font size.
Everything works, as long as the text is left-aligned. If I switch the text alignment to center, the text box appears in the right place, but the text is not center-aligned.
I tried to change the transformOrigin to “Item.Centerâ€, but this does not solve the problem.
Attached you can find an example featuring a text and a rectangle enclosing it:
Rectangle
{
id: rect
anchors.fill: testText
color: "yellow"
}
Text
{
id: testText
width: 100
height: 50
anchors.centerIn: parent
text: "example"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
scale: Math.min((width / paintedWidth), (height / paintedHeight))
transformOrigin: Item.Center // <- I've tried every point...
color: "black"
}
Rectangle
{
id: rect
anchors.fill: testText
color: "yellow"
}
Text
{
id: testText
width: 100
height: 50
anchors.centerIn: parent
text: "example"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
scale: Math.min((width / paintedWidth), (height / paintedHeight))
transformOrigin: Item.Center // <- I've tried every point...
color: "black"
}
To copy to clipboard, switch view to plain text mode
here you can see the (wrong) result: http://i59.tinypic.com/29c9ymg.jpg
Bookmarks