<?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[The role of QStandardItems]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">for a long time, I've stopped working on Qt projects and, again, I have to read lot about the basics.<br />
I'm writing a small project that handles some financials and I need a QTableView, for which I subclassed QStandardItemModel.</p>
<p dir="auto">My basic and maybe stupid question is: Do I mandatory need QStandardItems inside the views cells (or inside the model) to handle with the data or is it possible to store data "directly" into the cells? I'm asking that because while reading the documentation I see that it is recommended to generate TreeViews and ListViews empty and appendRows/Columns with directly insering items, while it is recommended for TableViews to scale directly with int row &amp; int column by constructing the model and inserting items with setItem.<br />
Well, I created such a QTableView with an (empty?) QStandardItemModel with 10x10 matrix and as I can see, without setting items, it is possible to double click a cell and store data. So, I'm asking myself if:<br />
a) there are QStandardItems generated by default for each index (cell) or<br />
b) if it is generated by the delegate while typing into the cell or<br />
c) there exists a way of directly storing data into the view (or model?) without having created corresponding items</p>
<p dir="auto">Can you help me with that, I don't find the answer in the docs, unfortunately.</p>
<p dir="auto">Thank you very much for your help!<br />
Kind regards<br />
Binary91</p>
]]></description><link>https://forum.qt.io/topic/138310/the-role-of-qstandarditems</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 14:07:14 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138310.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Aug 2022 13:46:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to The role of QStandardItems on Sat, 13 Aug 2022 14:26:07 GMT]]></title><description><![CDATA[<p dir="auto">Again, sorry for replying so late.</p>
<p dir="auto">Thank you very much for that hint using QSql itsself as a model. I will read the Qt documentation about that!</p>
<p dir="auto">Kind Regards,<br />
Binary</p>
]]></description><link>https://forum.qt.io/post/724729</link><guid isPermaLink="true">https://forum.qt.io/post/724729</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sat, 13 Aug 2022 14:26:07 GMT</pubDate></item><item><title><![CDATA[Reply to The role of QStandardItems on Sun, 07 Aug 2022 16:49:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/724054">The role of QStandardItems</a>:</p>
<blockquote>
<p dir="auto">So using the delegate is the only way of "automatically" creating "real items" that holds the data and no other containers exist in a QStandardItemModel that can hold data.</p>
</blockquote>
<p dir="auto">There is nothing magical here.  It's just that the <code>QTableView</code>/<code>Widget</code> editing delegate has <a href="https://doc.qt.io/qt-6/qabstractitemdelegate.html#setModelData" target="_blank" rel="noopener noreferrer nofollow ugc">QAbstractItemDelegate::setModelData()</a> method.  But you can always create/update <code>QStandardItem</code>s yourself via <code>QStandardItemModel</code> methods.  The view simply makes whatever appropriate calls to the model, nothing you cannot do explicitly.</p>
<blockquote>
<p dir="auto">I'd like to work with table data that I will store in a SQL database and load it into the model when I need it.</p>
</blockquote>
<p dir="auto">It would be simpler if you use Qt's <code>QSql...</code> classes, including models and queries, rather than extracting stuff out to copy into abstract or standard item models.  <code>QTableView</code> still works just as much with SQL models as item models.</p>
]]></description><link>https://forum.qt.io/post/724055</link><guid isPermaLink="true">https://forum.qt.io/post/724055</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 07 Aug 2022 16:49:55 GMT</pubDate></item><item><title><![CDATA[Reply to The role of QStandardItems on Sun, 07 Aug 2022 16:33:29 GMT]]></title><description><![CDATA[<p dir="auto">Hi JonB,<br />
sorry for the belated response. Ok, that sonds logical to me. So using the delegate is the only way of "automatically" creating "real items" that holds the data and no other containers exist in a QStandardItemModel that can hold data. That was what I needed to realize.</p>
<p dir="auto">Well, in your first response, you recommended to maybe create my own model by directly inheriting from QAbstractItemModel in case I'd have me own data storage or types. I'd like to work with table data that I will store in a SQL database and load it into the model when I need it. So far, I don't have specific item types, I'd try to work on the QStandardItem. Long time ago, I started a try of subclassing QAbstractItemModel and I realized that it is very hard work, especially handling inserting of new columns and stuff. I thought of QStandardItemModel to be such a basic subclass of it that already fits the generic stuff I need for my basic usage. Well, I'll maybe see it while using it...</p>
<p dir="auto">Anyway, thank you for your help!</p>
]]></description><link>https://forum.qt.io/post/724054</link><guid isPermaLink="true">https://forum.qt.io/post/724054</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sun, 07 Aug 2022 16:33:29 GMT</pubDate></item><item><title><![CDATA[Reply to The role of QStandardItems on Tue, 02 Aug 2022 22:41:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a><br />
So long as a row/column valid, <code>data(index)</code> will return an empty/invalid <code>QVariant()</code>.  That's probably what "an empty item" is.  The editor delegate will create a new item.</p>
]]></description><link>https://forum.qt.io/post/723629</link><guid isPermaLink="true">https://forum.qt.io/post/723629</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 02 Aug 2022 22:41:13 GMT</pubDate></item><item><title><![CDATA[Reply to The role of QStandardItems on Tue, 02 Aug 2022 20:17:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
thank you for your reply!<br />
Ok, so as the corresponding item object is created while using a delegate to store data into the views cells, I guess that there can't be data inside the view without a corresponding item object that holds it, right? I was just wondering why, in that case of behaviour, it is possible to retrive an item with a QModelIndex to an empty cell that never stored any data and that I never created an item by myself for...</p>
<p dir="auto">"<em>But if you have your own data storage/types already written then copying these to &amp; from QStandardItemModel can be wasteful. There you might want to write your own to inherit from QAbstractItemModel and operate directly on your own existing data for efficiency/type safety.</em>"</p>
<p dir="auto">Yes, you're right, I think I'll have to do it this way in future projects.. Thank you!</p>
]]></description><link>https://forum.qt.io/post/723622</link><guid isPermaLink="true">https://forum.qt.io/post/723622</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Tue, 02 Aug 2022 20:17:03 GMT</pubDate></item><item><title><![CDATA[Reply to The role of QStandardItems on Mon, 01 Aug 2022 14:17:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/723479">The role of QStandardItems</a>:</p>
<blockquote>
<p dir="auto">b) if it is generated by the delegate while typing into the cell or</p>
</blockquote>
<p dir="auto">This one.</p>
<p dir="auto"><code>QStandardItemModel</code> is just a <em>convenience</em> pre-supplied model which is generic.  It lets you easily create data items of any type, and it provides storage for any of the other roles' item data if desired (like color or size of checkability).  It provides the data storage.  You can also still use <code>data()</code>/<code>setData()</code> on the model if you don't want to go via "items".</p>
<p dir="auto">But if you have your <em>own</em> data storage/types already written then copying these to &amp; from <code>QStandardItemModel</code> can be wasteful.  There you might want to write your own to inherit from <code>QAbstractItemModel</code> and operate directly on your own existing data for efficiency/type safety.</p>
]]></description><link>https://forum.qt.io/post/723484</link><guid isPermaLink="true">https://forum.qt.io/post/723484</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 01 Aug 2022 14:17:07 GMT</pubDate></item></channel></rss>