<?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[How does a QTreeview get populated]]></title><description><![CDATA[<p dir="auto">I am trying to create a QAbstractProxyModel between an SQL table model and a QTreeview. The problem I'm having is that the base level items don't have the branch indicators to show it's children. All the data of the shown items looks fine.</p>
<p dir="auto">I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.</p>
<p dir="auto">The way I'm determining which level an item lives is by from the first column of the table which has a stirng like "0.0.1" for the first base item's first item's second item.</p>
]]></description><link>https://forum.qt.io/topic/108347/how-does-a-qtreeview-get-populated</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 15:39:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/108347.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Oct 2019 21:21:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How does a QTreeview get populated on Fri, 01 Nov 2019 08:51:57 GMT]]></title><description><![CDATA[<p dir="auto">So you have to override the <code>flag()</code> method to fix that</p>
]]></description><link>https://forum.qt.io/post/559407</link><guid isPermaLink="true">https://forum.qt.io/post/559407</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Fri, 01 Nov 2019 08:51:57 GMT</pubDate></item><item><title><![CDATA[Reply to How does a QTreeview get populated on Thu, 31 Oct 2019 21:23:16 GMT]]></title><description><![CDATA[<p dir="auto">So after some more digging I think I have found the problem, QTreeViewPrivate::hasVisibleChildren returns false for all base level items. Apparently 'ItemNeverHasChildren' is true. Which makes sense since the source model is a table.</p>
]]></description><link>https://forum.qt.io/post/559365</link><guid isPermaLink="true">https://forum.qt.io/post/559365</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 31 Oct 2019 21:23:16 GMT</pubDate></item><item><title><![CDATA[Reply to How does a QTreeview get populated on Thu, 31 Oct 2019 14:20:44 GMT]]></title><description><![CDATA[<p dir="auto">As a side note, the <a href="https://wiki.qt.io/Model_Test" target="_blank" rel="noopener noreferrer nofollow ugc">model test</a> is a great tool to debug custom models</p>
]]></description><link>https://forum.qt.io/post/559321</link><guid isPermaLink="true">https://forum.qt.io/post/559321</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Thu, 31 Oct 2019 14:20:44 GMT</pubDate></item><item><title><![CDATA[Reply to How does a QTreeview get populated on Thu, 31 Oct 2019 07:35:36 GMT]]></title><description><![CDATA[<p dir="auto">@Sillie_wous said in <a href="/post/559195">How does a QTreeview get populated</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> At which point do these functions get called so I can debug the issue?</p>
</blockquote>
<p dir="auto">They're called all the time. When view is initialised, when mouse hovers over the view, when focus changes - really they are typically called hundreds of times whenever you do anything in the app.</p>
<blockquote>
<p dir="auto">I've treid looking trough the source of QTreeView but don't see it anywhere. Now I just have a break point at those functions but they don't seem to get called from the base level items, only the root item.</p>
</blockquote>
<p dir="auto">The view starts at root item because initially it does not know anything more. So first, it will check <code>index(QModelIndex())</code> to get the root item (in QTreeView, the root is <strong>invisible</strong>!), then it will check if root has children, then it will call <code>index()</code> for all items, and it will call <code>data()</code> for all roles to get all data that needs to be displayed. Then rinse and repeat for all children, their children etc.</p>
]]></description><link>https://forum.qt.io/post/559201</link><guid isPermaLink="true">https://forum.qt.io/post/559201</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 31 Oct 2019 07:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to How does a QTreeview get populated on Thu, 31 Oct 2019 07:22:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> At which point do these functions get called so I can debug the issue? I've treid looking trough the source of QTreeView but don't see it anywhere. Now I just have a break point at those functions but they don't seem to get called from the base level items, only the root item.</p>
]]></description><link>https://forum.qt.io/post/559195</link><guid isPermaLink="true">https://forum.qt.io/post/559195</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Thu, 31 Oct 2019 07:22:17 GMT</pubDate></item><item><title><![CDATA[Reply to How does a QTreeview get populated on Thu, 31 Oct 2019 07:03:32 GMT]]></title><description><![CDATA[<p dir="auto">@Sillie_wous said in <a href="/post/559133">How does a QTreeview get populated</a>:</p>
<blockquote>
<p dir="auto">I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.</p>
</blockquote>
<p dir="auto">In your model, both <code>hasChildren()</code> and <code>rowCount()</code> need to return correct data for the hierarchy to be shown correctly in QTreeView. And yes, code in <code>index()</code> needs to be correct as well.</p>
]]></description><link>https://forum.qt.io/post/559185</link><guid isPermaLink="true">https://forum.qt.io/post/559185</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 31 Oct 2019 07:03:32 GMT</pubDate></item></channel></rss>