<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Scale centered text]]></title><description><![CDATA[<p dir="auto">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.<br />
I'd like to be able to operate directly on the scale property instead of changing the font size.</p>
<p dir="auto">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.<br />
I tried to change the transformOrigin to "Item.Center", but this does not solve the problem.</p>
<p dir="auto">Attached you can find an example featuring a text and a rectangle enclosing it:<br />
@    Rectangle<br />
{<br />
id: rect<br />
anchors.fill: testText<br />
color: "yellow"<br />
}</p>
<pre><code>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 // &lt;- I've tried every point...
    color: "black"
}@
</code></pre>
<p dir="auto">Result:<br />
!<a href="http://i59.tinypic.com/29c9ymg.jpg(http://i59.tinypic.com/29c9ymg.jpg)" target="_blank" rel="noopener noreferrer nofollow ugc">http://i59.tinypic.com/29c9ymg.jpg(http://i59.tinypic.com/29c9ymg.jpg)</a>!</p>
<p dir="auto">Thanks in advance</p>
]]></description><link>https://forum.qt.io/topic/44459/scale-centered-text</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 13:49:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/44459.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Aug 2014 08:58:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Scale centered text on Mon, 04 Aug 2014 11:16:07 GMT]]></title><description><![CDATA[<p dir="auto">The answer is... NO<br />
!<a href="http://i58.tinypic.com/2qu3xio.png(http://i58.tinypic.com/2qu3xio.png)" target="_blank" rel="noopener noreferrer nofollow ugc">http://i58.tinypic.com/2qu3xio.png(http://i58.tinypic.com/2qu3xio.png)</a>!</p>
<p dir="auto">Extra pixels still remains!<br />
Is this a QML bug?</p>
]]></description><link>https://forum.qt.io/post/238461</link><guid isPermaLink="true">https://forum.qt.io/post/238461</guid><dc:creator><![CDATA[nick85]]></dc:creator><pubDate>Mon, 04 Aug 2014 11:16:07 GMT</pubDate></item><item><title><![CDATA[Reply to Scale centered text on Mon, 04 Aug 2014 11:09:56 GMT]]></title><description><![CDATA[<p dir="auto">I found a workaround adding a wrapper Item and keeping Text auto-resizing:</p>
<p dir="auto">@    Rectangle<br />
{<br />
id: rect<br />
anchors.fill: textContainer<br />
color: "yellow"<br />
}</p>
<pre><code>Item
{
    id: textContainer

    width: 100
    height: 50

    anchors.centerIn: parent
}

Text
{
    id: testText

    // NOTE: auto width

    anchors.centerIn: textContainer

    text: "aa"
    //verticalAlignment: Text.AlignTop  // &lt;-- NOT NEEDED
    //horizontalAlignment: Text.AlignLeft   // &lt;-- NOT NEEDED

    scale: Math.min((textContainer.width / paintedWidth), (textContainer.height / paintedHeight))
    //transformOrigin: Item.Center   // &lt;-- NOT NEEDED
    color: "black"
}
</code></pre>
<p dir="auto">@</p>
<p dir="auto">This seems to work but vertical expansion still does not fill the whole height.<br />
Please correct me if I'm wrong, but I believe paintedHeight should be the height in pixel of the text being rendered.<br />
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.<br />
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?<br />
Thanks in advance.</p>
]]></description><link>https://forum.qt.io/post/238459</link><guid isPermaLink="true">https://forum.qt.io/post/238459</guid><dc:creator><![CDATA[nick85]]></dc:creator><pubDate>Mon, 04 Aug 2014 11:09:56 GMT</pubDate></item><item><title><![CDATA[Reply to Scale centered text on Mon, 04 Aug 2014 10:32:02 GMT]]></title><description><![CDATA[<p dir="auto">And in any case I don't know why but:<br />
@scale: Math.min((width / paintedWidth), (height / paintedHeight))@<br />
does not seem to work perfectly!</p>
<p dir="auto">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.</p>
<p dir="auto">But the result is !<a href="http://oi62.tinypic.com/2vvq0xs.jpg(http://oi62.tinypic.com/2vvq0xs.jpg)" target="_blank" rel="noopener noreferrer nofollow ugc">http://oi62.tinypic.com/2vvq0xs.jpg(http://oi62.tinypic.com/2vvq0xs.jpg)</a>!</p>
<p dir="auto">What is wrong?</p>
]]></description><link>https://forum.qt.io/post/238451</link><guid isPermaLink="true">https://forum.qt.io/post/238451</guid><dc:creator><![CDATA[nick85]]></dc:creator><pubDate>Mon, 04 Aug 2014 10:32:02 GMT</pubDate></item><item><title><![CDATA[Reply to Scale centered text on Mon, 04 Aug 2014 10:00:49 GMT]]></title><description><![CDATA[<p dir="auto">Update:<br />
I tried without text alignment or with only vertical alignment but It doesn't work:</p>
<p dir="auto">@        //verticalAlignment: Text.AlignVCenter<br />
//horizontalAlignment: Text.AlignHCenter@</p>
<p dir="auto">Result: !<a href="http://oi60.tinypic.com/24mgtn4.jpg(http://oi60.tinypic.com/24mgtn4.jpg)" target="_blank" rel="noopener noreferrer nofollow ugc">http://oi60.tinypic.com/24mgtn4.jpg(http://oi60.tinypic.com/24mgtn4.jpg)</a>!</p>
<p dir="auto">With only vertical alignment:</p>
<p dir="auto">@        verticalAlignment: Text.AlignVCenter<br />
//horizontalAlignment: Text.AlignHCenter@</p>
<p dir="auto">Result: !<a href="http://oi59.tinypic.com/25f6hro.jpg(http://oi59.tinypic.com/25f6hro.jpg)" target="_blank" rel="noopener noreferrer nofollow ugc">http://oi59.tinypic.com/25f6hro.jpg(http://oi59.tinypic.com/25f6hro.jpg)</a>!</p>
]]></description><link>https://forum.qt.io/post/238448</link><guid isPermaLink="true">https://forum.qt.io/post/238448</guid><dc:creator><![CDATA[nick85]]></dc:creator><pubDate>Mon, 04 Aug 2014 10:00:49 GMT</pubDate></item></channel></rss>