Thank you for the answer.
I tried but it does not seem to work well.
Without text alignments: http://i60.tinypic.com/24mgtn4.png
With only vertical center alignment: http://i59.tinypic.com/25f6hro.jpg
Added after 32 minutes:
And in any case I don't know why but:
scale: Math.min((width / paintedWidth), (height / paintedHeight))
scale: Math.min((width / paintedWidth), (height / paintedHeight))
To copy to clipboard, switch view to plain text mode
does not seem to work perfectly!
I tried with a vertical expansion changing the text to "aa". In this case, (width / paintedWidth) is greather than (height / paintedHeight), therefore the scale should be (height / paintedHeight) and I expect the text height will be the same as the box. But the result is: http://i62.tinypic.com/2vvq0xs.png
What is wrong in scale computation?
Added after 27 minutes:
I found a workaround adding a wrapper Item and keeping Text auto-resizing:
Rectangle
{
id: rect
anchors.fill: textContainer
color: "yellow"
}
Item
{
id: textContainer
width: 100
height: 50
anchors.centerIn: parent
}
Text
{
id: testText
// NOTE: auto width
anchors.centerIn: textContainer
text: "aa"
//verticalAlignment: Text.AlignTop // <-- NOT NEEDED
//horizontalAlignment: Text.AlignLeft // <-- NOT NEEDED
scale: Math.min((textContainer.width / paintedWidth), (textContainer.height / paintedHeight))
//transformOrigin: Item.Center // <-- NOT NEEDED
color: "black"
}
Rectangle
{
id: rect
anchors.fill: textContainer
color: "yellow"
}
Item
{
id: textContainer
width: 100
height: 50
anchors.centerIn: parent
}
Text
{
id: testText
// NOTE: auto width
anchors.centerIn: textContainer
text: "aa"
//verticalAlignment: Text.AlignTop // <-- NOT NEEDED
//horizontalAlignment: Text.AlignLeft // <-- NOT NEEDED
scale: Math.min((textContainer.width / paintedWidth), (textContainer.height / paintedHeight))
//transformOrigin: Item.Center // <-- NOT NEEDED
color: "black"
}
To copy to clipboard, switch view to plain text mode
This seems to work but vertical expansion still does not fill the whole height.
Please correct me if I'm wrong, but I believe paintedHeight should be the height in pixel of the text being rendered.
However, this does not seem the case, as a border of a few pixels still remains, both in the upper and the lower part of the rectangle.
Is this behavior due to the render engine leaving a few extra pixels for characters potentially higher than 'a' (e.g., 't' or 'q'), since the font being used is not monospace?
Thanks in advance.
Added after 21 minutes:
The answer is… NO
http://oi58.tinypic.com/2qu3xio.jpg
Is this a QML bug?
Bookmarks