<?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[Why is custom tree item data undefined when tree node collapses?]]></title><description><![CDATA[<p dir="auto">I'm using QAbstractItemModel.</p>
<p dir="auto"><img src="https://s1.ax1x.com/2020/09/19/w5UIN4.jpg" alt="w5UIN4.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://s1.ax1x.com/2020/09/19/w5U5EF.jpg" alt="w5U5EF.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://s1.ax1x.com/2020/09/19/w5Uo4J.jpg" alt="w5Uo4J.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto">The reference sample.<br />
<a href="https://github.com/hvoigt/qt-qml-treeview/blob/master/TreeDelegate.qml" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/hvoigt/qt-qml-treeview/blob/master/TreeDelegate.qml</a></p>
]]></description><link>https://forum.qt.io/topic/119130/why-is-custom-tree-item-data-undefined-when-tree-node-collapses</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 13:04:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/119130.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Sep 2020 02:46:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Mon, 21 Sep 2020 10:00:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mirro">@<bdi>mirro</bdi></a> said in <a href="/post/618058">Why is custom tree item data undefined when tree node collapses?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a>  Oh, Do you mean that the QML calls the C++ QAbstractItemModel methods for processing?</p>
</blockquote>
<p dir="auto">I don't know your code structure. My assumption was that you are using QAbstractItemModel and your radio button state is controlled by <code>CheckStateRole</code>.</p>
<p dir="auto">If, on the other hand, you are using some different mechanism, you need to adapt to that. But definitely, regardless of the mechanism - changing a state (any kind of state - item name, check state, color etc.) is a job of the model (or underlying data), not the view.</p>
]]></description><link>https://forum.qt.io/post/618063</link><guid isPermaLink="true">https://forum.qt.io/post/618063</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 21 Sep 2020 10:00:15 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Mon, 21 Sep 2020 09:55:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a>  Oh, Do you mean that the QML calls the C++ QAbstractItemModel methods for processing?</p>
]]></description><link>https://forum.qt.io/post/618058</link><guid isPermaLink="true">https://forum.qt.io/post/618058</guid><dc:creator><![CDATA[mirro]]></dc:creator><pubDate>Mon, 21 Sep 2020 09:55:03 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Mon, 21 Sep 2020 05:52:45 GMT]]></title><description><![CDATA[<p dir="auto">You need to do it in the model, for sure. This stuff belongs to <code>setData()</code> method in the model.</p>
]]></description><link>https://forum.qt.io/post/618008</link><guid isPermaLink="true">https://forum.qt.io/post/618008</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 21 Sep 2020 05:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Mon, 21 Sep 2020 01:50:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> Hi~So how do I make it so that when I check the main node, all the children are checked together?</p>
<p dir="auto"><img src="https://s1.ax1x.com/2020/09/21/wHpiC9.jpg" alt="wHpiC9.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/617995</link><guid isPermaLink="true">https://forum.qt.io/post/617995</guid><dc:creator><![CDATA[mirro]]></dc:creator><pubDate>Mon, 21 Sep 2020 01:50:54 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Sun, 20 Sep 2020 05:08:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mirro">@<bdi>mirro</bdi></a> said in <a href="/post/617913">Why is custom tree item data undefined when tree node collapses?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> Thank you for your question and answer.</p>
<p dir="auto">What method can I use to traverse the children under the selected node in QML?</p>
</blockquote>
<p dir="auto">Don't do it unless you have to - it's too error prone with delegates coming in and out of existence all the time.</p>
<blockquote>
<p dir="auto">Do I need to add methods to the QAbstractItemModel in C++ ?</p>
<pre><code>MouseArea{
    OnPressed:{
             //...
             if(styleData.depth === 1)
             {
                      var curIndex = treeView.indexAt(mouse.x,mouse.y)
             }
    }
}
</code></pre>
</blockquote>
<p dir="auto">Move your <code>MouseArea</code> into the delegate - this way you don't have to find which index and item is affected, because <code>pressed</code> signal will be emitted and handled directly in the item which was clicked.</p>
]]></description><link>https://forum.qt.io/post/617915</link><guid isPermaLink="true">https://forum.qt.io/post/617915</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sun, 20 Sep 2020 05:08:37 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Sun, 20 Sep 2020 03:27:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> Thank you for your question and answer.</p>
<p dir="auto">What method can I use to traverse the children under the selected node in QML?<br />
Do I need to add methods to the QAbstractItemModel in C++ ?</p>
<pre><code>MouseArea{
    OnPressed:{
             //...
             if(styleData.depth === 1)
             {
                      var curIndex = treeView.indexAt(mouse.x,mouse.y)
             }
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/617913</link><guid isPermaLink="true">https://forum.qt.io/post/617913</guid><dc:creator><![CDATA[mirro]]></dc:creator><pubDate>Sun, 20 Sep 2020 03:27:15 GMT</pubDate></item><item><title><![CDATA[Reply to Why is custom tree item data undefined when tree node collapses? on Sat, 19 Sep 2020 16:47:25 GMT]]></title><description><![CDATA[<p dir="auto">When delegate stops being shown (moves off screen, is clipped or collapsed) QML engine usually destroys it. And on model side, collapsed indexes are invalid so <code>data()</code> will return empty <code>QVariant</code>.</p>
<p dir="auto">Do this to get rid of the warning:</p>
<pre><code>text: styleData === undefined? "" : styleData.value.name
</code></pre>
<p dir="auto">(and please, please: paste <em><strong>text</strong></em> not pictures where you want to show code! It's much easier for me to then copy-paste your code and show tweaks or corrections)</p>
]]></description><link>https://forum.qt.io/post/617856</link><guid isPermaLink="true">https://forum.qt.io/post/617856</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sat, 19 Sep 2020 16:47:25 GMT</pubDate></item></channel></rss>