<?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[Am I using &#96;TreeView&#96; right?]]></title><description><![CDATA[<p dir="auto">I am following the <a href="https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/simpletreemodel?h=6.10" target="_blank" rel="noopener noreferrer nofollow ugc">official example for populating a TreeView or QTreeView</a> from Qt and getting to a result. To do that I am subclassing <code>QAbstractItemModel</code> (which is supposedly a flat table, not a classical tree structure) and copying a lot of custom code from the example, such as <code>TreeItem</code>.</p>
<p dir="auto">This approach is fine for one treeview, however it feels a little bit artificial with Qt, and could get quite verbose if an application uses TreeView a lot.</p>
<p dir="auto">I wonder whether professional Qt apps also use this method from the example, or whether they do something else? I am thinking of <code>friction2d</code>, an open-source Qt app. They use <code>QTreeView</code> a lot but I searched in their code and found no mention of subclassing <code>QAbstractItemModel</code> anywhere!</p>
<p dir="auto">I think I should just be able to subclass a <code>QTreeModel</code>, populate it with data (e.g. via a <code>QList&lt;QVariant&gt;</code>), and call it a day.</p>
<p dir="auto">I also have another question: I need this TreeView to be interactive. So, for example, you should be able to select certain elements in the tree, be able to right-click them and open menu popups, etc. Are there any examples available that teach how to do this?</p>
]]></description><link>https://forum.qt.io/topic/164305/am-i-using-treeview-right</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 05:01:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164305.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 22 Feb 2026 17:22:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Fri, 27 Feb 2026 12:25:48 GMT]]></title><description><![CDATA[<p dir="auto">Nevermind, I was using <code>QAbstractItemModel</code> when I should've used <code>QStandardItemModel</code>. Thanks!</p>
]]></description><link>https://forum.qt.io/post/836642</link><guid isPermaLink="true">https://forum.qt.io/post/836642</guid><dc:creator><![CDATA[kaixoo]]></dc:creator><pubDate>Fri, 27 Feb 2026 12:25:48 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Fri, 27 Feb 2026 12:40:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/836489">Am I using &amp;#x60;TreeView&amp;#x60; right?</a>:</p>
<blockquote>
<p dir="auto">Or, for a QTreeView model start from a QStandardItemModel Class.</p>
</blockquote>
]]></description><link>https://forum.qt.io/post/836643</link><guid isPermaLink="true">https://forum.qt.io/post/836643</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 27 Feb 2026 12:40:15 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Fri, 27 Feb 2026 12:25:48 GMT]]></title><description><![CDATA[<p dir="auto">Nevermind, I was using <code>QAbstractItemModel</code> when I should've used <code>QStandardItemModel</code>. Thanks!</p>
]]></description><link>https://forum.qt.io/post/836642</link><guid isPermaLink="true">https://forum.qt.io/post/836642</guid><dc:creator><![CDATA[kaixoo]]></dc:creator><pubDate>Fri, 27 Feb 2026 12:25:48 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Thu, 26 Feb 2026 15:45:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> QRangeModel might be what I'm looking for!</p>
<p dir="auto">Do you know how custom behaviour can be implemented in a TreeView? I haven't found information online, but it's basically features like right clicking to open a Menu, double clicking to rename, key shortcuts to delete...</p>
<p dir="auto">This is going to be for the Assets dialog of my application, which is basically a list that displays all the files that are imported into the current file. Something like the following:</p>
<pre><code>- Compositions
   [x] Active composition
   [ ] Composition 1
   [ ] Composition 2
   ...
- Images
  - Image1
  - Image2
</code></pre>
]]></description><link>https://forum.qt.io/post/836608</link><guid isPermaLink="true">https://forum.qt.io/post/836608</guid><dc:creator><![CDATA[kaixoo]]></dc:creator><pubDate>Thu, 26 Feb 2026 15:45:06 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Mon, 23 Feb 2026 10:17:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kaixoo">@<bdi>kaixoo</bdi></a> said in <a href="/post/836497">Am I using &amp;#x60;TreeView&amp;#x60; right?</a>:</p>
<blockquote>
<p dir="auto">I am using QML's TreeView and it's only rendering children of the QAbstractItemModel, not elements further below.</p>
</blockquote>
<p dir="auto">That's incorrect.</p>
<p dir="auto">QRangeModel might be of help to avoid having to write the boilerplate.</p>
]]></description><link>https://forum.qt.io/post/836503</link><guid isPermaLink="true">https://forum.qt.io/post/836503</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Mon, 23 Feb 2026 10:17:51 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Mon, 23 Feb 2026 06:13:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kaixoo">@<bdi>kaixoo</bdi></a> said in <a href="/post/836497">Am I using &amp;#x60;TreeView&amp;#x60; right?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy_k">@<bdi>jeremy_k</bdi></a> I get that. I just think it's a bit odd that I have to implement <code>TreeItem</code> myself.</p>
</blockquote>
<p dir="auto">That just an example, rather than the only option. QStandardItemModel and QStandardItem can be used without much code.</p>
<pre><code>#include &lt;QApplication&gt;
#include &lt;QStandardItem&gt;
#include &lt;QStandardItemModel&gt;
#include &lt;QTreeView&gt;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QStandardItemModel model;
    model.appendRow(new QStandardItem("parent"));
    model.item(0)-&gt;appendRow(new QStandardItem("child"));
    QTreeView view;
    view.setModel(&amp;model);
    view.show();
    return a.exec();
}
</code></pre>
<blockquote>
<p dir="auto">I am using QML's <code>TreeView</code> and it's only rendering children of the <code>QAbstractItemModel</code>, not elements further below.</p>
</blockquote>
<p dir="auto">I'm having trouble parsing this. Does <code>elements further below</code> mean children of top level items? Is the lack of rendering intentional. or a bug in search of a fix? A minimal working example would help.</p>
]]></description><link>https://forum.qt.io/post/836499</link><guid isPermaLink="true">https://forum.qt.io/post/836499</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Mon, 23 Feb 2026 06:13:45 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Mon, 23 Feb 2026 03:47:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy_k">@<bdi>jeremy_k</bdi></a> I get that. I just think it's a bit odd that I have to implement <code>TreeItem</code> myself.</p>
<p dir="auto">I am using QML's <code>TreeView</code> and it's only rendering children of the <code>QAbstractItemModel</code>, not elements further below.</p>
]]></description><link>https://forum.qt.io/post/836497</link><guid isPermaLink="true">https://forum.qt.io/post/836497</guid><dc:creator><![CDATA[kaixoo]]></dc:creator><pubDate>Mon, 23 Feb 2026 03:47:03 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Mon, 23 Feb 2026 02:43:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kaixoo">@<bdi>kaixoo</bdi></a> said in <a href="/post/836488">Am I using &amp;#x60;TreeView&amp;#x60; right?</a>:</p>
<blockquote>
<p dir="auto">[...] I am subclassing <code>QAbstractItemModel</code> (which is supposedly a flat table, not a classical tree structure)</p>
</blockquote>
<p dir="auto">This is a misunderstanding. Each cell in the model can have children. For example:</p>
<pre><code>QModelIndex root = model-&gt;index(0, 0, nullptr);
QModelIndex firstChild = model-&gt;index(0, 0, root);
QModelIndex secondGrandChild = model-&gt;index(0, 1, firstChild);
</code></pre>
<p dir="auto">The custom followed by QTreeView, QTreeWidget, and I believe the Quick TreeView is to look for children under column zero in each row.</p>
]]></description><link>https://forum.qt.io/post/836495</link><guid isPermaLink="true">https://forum.qt.io/post/836495</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Mon, 23 Feb 2026 02:43:14 GMT</pubDate></item><item><title><![CDATA[Reply to Am I using &#96;TreeView&#96; right? on Sun, 22 Feb 2026 18:25:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kaixoo">@<bdi>kaixoo</bdi></a> said in <a href="/post/836488">Am I using &amp;#x60;TreeView&amp;#x60; right?</a>:</p>
<blockquote>
<p dir="auto">I think I should just be able to subclass a QTreeModel, populate it with data (e.g. via a QList&lt;QVariant&gt;), and call it a day.</p>
</blockquote>
<p dir="auto">For your usage, have you looked at just using the <a href="https://doc.qt.io/qt-6/qtreewidget.html" target="_blank" rel="noopener noreferrer nofollow ugc">QTreeWidget Class</a>?  That is a <code>QTreeView</code> with a simple model of <code>QVariant</code>s built into it.  Or, for a <code>QTreeView</code> model start from a <a href="https://doc.qt.io/qt-6/qstandarditemmodel.html" target="_blank" rel="noopener noreferrer nofollow ugc">QStandardItemModel Class</a>.</p>
]]></description><link>https://forum.qt.io/post/836489</link><guid isPermaLink="true">https://forum.qt.io/post/836489</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 22 Feb 2026 18:25:32 GMT</pubDate></item></channel></rss>