<?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[Resize items given absolute positions and sizes]]></title><description><![CDATA[<p dir="auto">I read this page: <a href="https://doc.qt.io/qt-5/scalability.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/scalability.html</a> but I still don't understand something that should be easy.<br />
My QML root page is displayed into a <code>QQuickWidget</code>, with <code>resizeMode == SizeRootObjectToView</code>.<br />
The root page contains an <code>Image</code> and its size is known - say 1920x1080.<br />
This image is anchored to fill the parent, so it scale according to the main window.</p>
<p dir="auto">Fine.<br />
The issues rise when I have to add the other objects: images or text, mainly.<br />
I receive a bitmap with their absolute positions and sizes <em>referred to the original background image</em> (1920x1080).</p>
<p dir="auto">As you understand I need to scale everything in order to keep their correct appearance.<br />
I thought it was simple:</p>
<pre><code>property real ratio: root.width / 1920
property real img1_X: 330 // absolute position
property real img1_Y: 200

Image {
    x: img1_X * ratio
    y: img1_Y * ratio
    scale: ratio
}
</code></pre>
<p dir="auto">but when I change the size of the viewport <code>ratio</code> doesn't change. It changes when I maximize or restore my <code>QMainWindow</code> but not when I resize it manually. Anyway, the images that are anchored to fill the root item are correctly resized every-time.</p>
<p dir="auto">What am I missing here?</p>
]]></description><link>https://forum.qt.io/topic/99745/resize-items-given-absolute-positions-and-sizes</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 16:58:42 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/99745.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Feb 2019 20:23:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Resize items given absolute positions and sizes on Sat, 16 Feb 2019 15:08:28 GMT]]></title><description><![CDATA[<p dir="auto">I solved putting everything into an <code>Item</code>and then applying the transformation needed:</p>
<pre><code>property real ratio: imgBackground.paintedWidth / 1920.0
property real xBase: (root.width - imgBackground.paintedWidth) / 2.0
property real yBase: (root.height - imgBackground.paintedHeight) / 2.0

Item {
    x: 0; y: 0
    width: 1920
    height: 1080

    transform: [
        Scale { xScale: ratio; yScale: ratio},
        Translate { x: xBase; y: yBase }
    ]

    // objects with absolute position and size
}
</code></pre>
]]></description><link>https://forum.qt.io/post/511909</link><guid isPermaLink="true">https://forum.qt.io/post/511909</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Sat, 16 Feb 2019 15:08:28 GMT</pubDate></item></channel></rss>