<?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[Fit the size to the parent for QQuickItem C++ Object]]></title><description><![CDATA[<p dir="auto">My environment is Qt 5.4 desktop MSVC2013 and QtQuick 2.4 on Windows 8.1 64bit.</p>
<p dir="auto">I want to fill the custom qml object extended by QQuickItem on the parent and I wrote the code like this.</p>
<pre><code>//QQuickItem *item;
item-&gt;setParentItem(parentItem);
(*case 1)
item-&gt;setProperty("anchors.fill", "parent");
(*case 2)
item-&gt;setProperty("width", "parent.width");
item-&gt;setProperty("height", "parent.height");
</code></pre>
<p dir="auto">But, those didn't work. If these ways cannot be used, is there any way alternative to implementing it only by C++?</p>
]]></description><link>https://forum.qt.io/topic/55537/fit-the-size-to-the-parent-for-qquickitem-c-object</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 17:47:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/55537.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Jun 2015 13:58:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fit the size to the parent for QQuickItem C++ Object on Wed, 24 Jun 2015 07:29:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/tank2005">@<bdi>Tank2005</bdi></a>,<br />
AFAIK setting <code>anchors</code> wont work from C++ side. You have to either do it on QML side or you can calculate the <code>x</code> and <code>y</code> positions programmatically on C++ side and set them. The latter can be done following way:</p>
<pre><code>child-&gt;setProperty("x",parentItem-&gt;width()/2-child-&gt;width()/2); //calculate and set
child-&gt;setProperty("y",parentItem-&gt;height()/2-child-&gt;height()/2);

</code></pre>
<p dir="auto">Edit: Since you want to fill you can use <code>parentItem</code>'s <code>width</code> and <code>height</code></p>
<pre><code>item-&gt;setProperty("width", parentItem.width);
item-&gt;setProperty("height", parentItem.height);
</code></pre>
]]></description><link>https://forum.qt.io/post/279260</link><guid isPermaLink="true">https://forum.qt.io/post/279260</guid><dc:creator><![CDATA[p3c0]]></dc:creator><pubDate>Wed, 24 Jun 2015 07:29:22 GMT</pubDate></item></channel></rss>