<?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 to pass QSqlTableModel::primaryKey().index to QSqlTableModel.setHeaderData(index) to set an icon ?]]></title><description><![CDATA[<p dir="auto"><a href="https://github.com/sonichy/HTYSQL" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/sonichy/HTYSQL</a><br />
<img src="https://s1.ax1x.com/2020/06/14/NSmiKx.png" alt="替代文字" class=" img-fluid img-markdown" /></p>
<pre><code>QSqlIndex sqlIndex = tableModel-&gt;primaryKey();
//int index = sqlIndex
tableModel-&gt;setHeaderData(index, Qt::Horizontal, QVariant::fromValue(QIcon(":/key.png")), Qt::DecorationRole);
</code></pre>
]]></description><link>https://forum.qt.io/topic/115860/how-to-pass-qsqltablemodel-primarykey-index-to-qsqltablemodel-setheaderdata-index-to-set-an-icon</link><generator>RSS for Node</generator><lastBuildDate>Mon, 02 Nov 2026 18:18:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/115860.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Jun 2020 11:51:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to pass QSqlTableModel::primaryKey().index to QSqlTableModel.setHeaderData(index) to set an icon ? on Mon, 22 Jun 2020 15:36:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sonichy">@<bdi>sonichy</bdi></a> Solved !</p>
<pre><code>QSqlIndex sqlIndex = tableModel-&gt;primaryKey();
qDebug() &lt;&lt; sqlIndex;
for (int i=0; i&lt;sqlIndex.count(); i++) {
    for (int c=0; c&lt;tableModel-&gt;columnCount(); c++) {
        QString header = tableModel-&gt;headerData(c, Qt::Horizontal, Qt::DisplayRole).toString();
        if (header == sqlIndex.fieldName(i)) {
            tableModel-&gt;setHeaderData(c, Qt::Horizontal, QVariant::fromValue(QIcon(":/key.png")), Qt::DecorationRole);
        }
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/602269</link><guid isPermaLink="true">https://forum.qt.io/post/602269</guid><dc:creator><![CDATA[sonichy]]></dc:creator><pubDate>Mon, 22 Jun 2020 15:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to How to pass QSqlTableModel::primaryKey().index to QSqlTableModel.setHeaderData(index) to set an icon ? on Sun, 14 Jun 2020 18:10:34 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I think the simpler way of doing that is to use a <a href="https://doc.qt.io/qt-5/qidentityproxymodel.html" target="_blank" rel="noopener noreferrer nofollow ugc">QIdentityProxyModel</a>. Reimplement the headerData method and return the custom values you want for the colums you want to modify and the original values for the others.</p>
]]></description><link>https://forum.qt.io/post/600671</link><guid isPermaLink="true">https://forum.qt.io/post/600671</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 14 Jun 2020 18:10:34 GMT</pubDate></item></channel></rss>