<?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[Populating a QStandardItemModel with data]]></title><description><![CDATA[<p dir="auto">Please help with populating a QTableWidget with data from a QStandardItemModel. I have looked at the documentation and can't seem to figure it out. This is my attempt at it:</p>
<p dir="auto">@void Widget::setupGui()<br />
{<br />
model = new QStandardItemModel(this);<br />
model-&gt;setColumnCount(4);<br />
model-&gt;setHeaderData(0,Qt::Horizontal,QString("Composer"),Qt::DisplayRole);<br />
model-&gt;setHeaderData(1,Qt::Horizontal,QString("Album Title"),Qt::DisplayRole);<br />
model-&gt;setHeaderData(2,Qt::Horizontal,QString("Replacement Cost"),Qt::DisplayRole);<br />
model-&gt;setHeaderData(3,Qt::Horizontal,QString("Rating"),Qt::DisplayRole);<br />
QHeaderView* hv = ui-&gt;tableWidget-&gt;horizontalHeader();<br />
hv-&gt;setResizeMode(QHeaderView::ResizeToContents);<br />
hv-&gt;setStretchLastSection(true);</p>
<pre><code>CDInfo *cd1 = new CDInfo("Abba","Essential Collection",120.89,7);
CDInfo *cd2 = new CDInfo("Hugh Masekela","Jabulani",199.05,6);
CDInfo *cd3 = new CDInfo("Karl Jenkins","Stabat Mater",256.00,9);

for (int row = 0; row &lt; 3; ++row) {
            for (int column = 0; column &lt; 4; ++column) {
                QModelIndex index = model-&gt;index(row, column, QModelIndex());
                model-&gt;setData(index, QVariant((row+1) * (column+1)));
            }
        }

ui-&gt;tableWidget-&gt;setModel(model);
</code></pre>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/topic/38031/populating-a-qstandarditemmodel-with-data</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 11:57:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/38031.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Feb 2014 11:11:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Populating a QStandardItemModel with data on Wed, 19 Feb 2014 14:21:51 GMT]]></title><description><![CDATA[<p dir="auto">oh alright thanks</p>
]]></description><link>https://forum.qt.io/post/215495</link><guid isPermaLink="true">https://forum.qt.io/post/215495</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 19 Feb 2014 14:21:51 GMT</pubDate></item><item><title><![CDATA[Reply to Populating a QStandardItemModel with data on Wed, 19 Feb 2014 14:15:56 GMT]]></title><description><![CDATA[<p dir="auto">No, I am just asking why you are using a QTableWidget since your are using a QStandardItemModel.</p>
<p dir="auto">Either use QTableView + QStandardItemModel or use only QTableWidget.</p>
<p dir="auto">QTableWidget already has a model</p>
]]></description><link>https://forum.qt.io/post/215492</link><guid isPermaLink="true">https://forum.qt.io/post/215492</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 19 Feb 2014 14:15:56 GMT</pubDate></item><item><title><![CDATA[Reply to Populating a QStandardItemModel with data on Wed, 19 Feb 2014 14:12:33 GMT]]></title><description><![CDATA[<p dir="auto">Are you saying that it can't be done with a QStandardItemModel?</p>
]]></description><link>https://forum.qt.io/post/215490</link><guid isPermaLink="true">https://forum.qt.io/post/215490</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 19 Feb 2014 14:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to Populating a QStandardItemModel with data on Wed, 19 Feb 2014 13:06:47 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Since you have a QStandardItemModel, why don't you use a QTableView ?</p>
]]></description><link>https://forum.qt.io/post/215473</link><guid isPermaLink="true">https://forum.qt.io/post/215473</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 19 Feb 2014 13:06:47 GMT</pubDate></item></channel></rss>