<?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[QTreeWidget and setItemWidget]]></title><description><![CDATA[<p dir="auto">My GUI requires a tree-view with lists inside that the user can interact with. So I've added a QTreeWidget in which every top level item has one child-item that I use setItemWidget on to add a QListWidget.<br />
However in the documentation it does say: "<em>This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead."</em></p>
<p dir="auto">You can't exactly call a QListWidget <em>static content</em>, but why shouldn't you do this? And should I really change to QTreeView and subclass QItemDelegate instead?</p>
]]></description><link>https://forum.qt.io/topic/69566/qtreewidget-and-setitemwidget</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 07:26:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69566.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Jul 2016 15:14:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTreeWidget and setItemWidget on Sat, 23 Jul 2016 22:41:50 GMT]]></title><description><![CDATA[<h2>hi<br />
well with 20 items, all should be golden. Also on desktop class pcs, it takes many rows before it get heavy, but say you target a<br />
mobile platform, it might be far less.</h2>
<p dir="auto">The list owns the items+any widget and will delete them so you need not to care for it.</p>
<p dir="auto">One exception is if you use the setData function and give it pointer to some class.<br />
It will not delete such class.<br />
I mention this as the setData/data function is very handy to add info to items, say to map it back to some data structure so<br />
often used.</p>
]]></description><link>https://forum.qt.io/post/339051</link><guid isPermaLink="true">https://forum.qt.io/post/339051</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 23 Jul 2016 22:41:50 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeWidget and setItemWidget on Sat, 23 Jul 2016 20:36:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a>  Thank you :)</p>
<blockquote>
<p dir="auto">well its not that it will explode or be really bad to use</p>
</blockquote>
<p dir="auto">Heh okay that's just what I wanted to know ;)<br />
It's just, it works pretty good like it currently is and I just think it would be a  major hassle to change it all to work properly with view + delegate and I doubt it would improve the performance much at all because my lists won't contain more than ~20 items at a time.</p>
<p dir="auto">I have another question though because I'm not quite sure if my program might have a memory leak.<br />
I have two tabs, when I click on a tab I want to delete all the items in the treewidget and then add the new items depending on which tab I pressed.<br />
This is an example of how I add my ListWidgets:</p>
<pre><code>QTreeWidgetItem *itemToplevel = new QTreeWidgetItem();
itemTopLevel-&gt;setText(0, "Top level item");

QTreeWidgetItem *itemListContainer = new QTreeWidgetItem();
itemTopLevel-&gt;addChild(itemListContainer);

ui-&gt;treeWidget-&gt;addTopLevelItem(itemTopLevel);

QListWidget *list = new QListWidget();
ui-&gt;treeWidget-&gt;setItemWidget(itemListContainer, 0, list);
</code></pre>
<p dir="auto">And then I add items to that list. Now, when I want to delete everything again before doing this again for the other tab, I call:</p>
<pre><code>ui-treeWidget-&gt;clear();
</code></pre>
<p dir="auto">In the documentation for the QTreeWidget for setItemWidget it says:</p>
<blockquote>
<p dir="auto">Note: The tree takes ownership of the widget.</p>
</blockquote>
<p dir="auto">So by calling <em>clear</em> on the tree widget I expect it to delete the list I've added (Including its items) and then of course the top-level items and their childs.<br />
Is this correct? Or am I responsible for any of it?</p>
]]></description><link>https://forum.qt.io/post/339038</link><guid isPermaLink="true">https://forum.qt.io/post/339038</guid><dc:creator><![CDATA[Denjas]]></dc:creator><pubDate>Sat, 23 Jul 2016 20:36:16 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeWidget and setItemWidget on Sat, 23 Jul 2016 18:24:19 GMT]]></title><description><![CDATA[<p dir="auto">hi and welcome</p>
<p dir="auto">well its not that it will explode or be really bad to use<br />
ListWidget + setItemWidget<br />
but view+delegate is design for such use case<br />
and have far better performance once u have many items.</p>
<p dir="auto">something like<br />
<a href="http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html</a></p>
<p dir="auto">Also the views helps editing etc whereas listwidget+setItem is more raw for many operations.</p>
<p dir="auto">But you should just test it out with listwidget and if it dont live up to the specs,<br />
the view+delegate will provide.</p>
]]></description><link>https://forum.qt.io/post/339033</link><guid isPermaLink="true">https://forum.qt.io/post/339033</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sat, 23 Jul 2016 18:24:19 GMT</pubDate></item></channel></rss>