<?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[QTableView: select row with a specific id]]></title><description><![CDATA[<p dir="auto">After sorting (i.e. <code>ui-&gt;table-&gt;sortByColumn(MODEL_PACKAGES_COL_NAME)</code>) the order of the rows in the <code>QTableView</code> may be different than those in the model. If I need to select (highlight) a row with a specific id, I do this:</p>
<pre><code>void DialogPackages::selectId(int id)
{
    for (int i = 0; i &lt; _model-&gt;rowCount(); i++)
    {
        QModelIndex index = _model-&gt;index(i, MODEL_PACKAGES_COL_ID);
        if (id == _model-&gt;data(index)) ui-&gt;table-&gt;selectRow(i);
    }
}
</code></pre>
<p dir="auto">it works, but I wonder if there's something better to avoid to cycle all the rows every time.</p>
]]></description><link>https://forum.qt.io/topic/108685/qtableview-select-row-with-a-specific-id</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 19:28:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/108685.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Nov 2019 11:34:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTableView: select row with a specific id on Sun, 10 Nov 2019 12:33:39 GMT]]></title><description><![CDATA[<p dir="auto">Maybe QAbstractItemModel::match() - but custom stuff is faster I would guess</p>
]]></description><link>https://forum.qt.io/post/560942</link><guid isPermaLink="true">https://forum.qt.io/post/560942</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 10 Nov 2019 12:33:39 GMT</pubDate></item><item><title><![CDATA[Reply to QTableView: select row with a specific id on Sun, 10 Nov 2019 12:30:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/560939">QTableView: select row with a specific id</a>:</p>
<blockquote>
<p dir="auto">build-in - no since it's your data, not something Qt has control of it.</p>
</blockquote>
<p dir="auto">Not actually, I thought about a generic method like this:</p>
<pre><code>int QTableView::findRow(int col, QVariant data);
</code></pre>
<p dir="auto">it would return the (first) row number where <code>data</code> is present into column <code>col</code>. -1 otherwise.<br />
Or a more generic one:</p>
<pre><code>QList&lt;int&gt; QTableView::findRows(int col, QVariant data);
</code></pre>
<p dir="auto">of course it's trivial to implement them in a rough way like I did above.<br />
I was just afraid I didn't search well the documentation.</p>
]]></description><link>https://forum.qt.io/post/560941</link><guid isPermaLink="true">https://forum.qt.io/post/560941</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Sun, 10 Nov 2019 12:30:03 GMT</pubDate></item><item><title><![CDATA[Reply to QTableView: select row with a specific id on Sun, 10 Nov 2019 12:23:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark81">@<bdi>Mark81</bdi></a> said in <a href="/post/560937">QTableView: select row with a specific id</a>:</p>
<blockquote>
<p dir="auto">there are no efficient find methods built-in.</p>
</blockquote>
<p dir="auto">build-in - no since it's your data, not something Qt has control of it.</p>
]]></description><link>https://forum.qt.io/post/560939</link><guid isPermaLink="true">https://forum.qt.io/post/560939</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 10 Nov 2019 12:23:39 GMT</pubDate></item><item><title><![CDATA[Reply to QTableView: select row with a specific id on Sun, 10 Nov 2019 12:13:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/560936">QTableView: select row with a specific id</a>:</p>
<blockquote>
<p dir="auto">I don't see another way, apart from that you should break out once the row is found.</p>
</blockquote>
<p dir="auto">Yep, of course I forgot to break the loop.<br />
In other words, there are no efficient find methods built-in.</p>
]]></description><link>https://forum.qt.io/post/560937</link><guid isPermaLink="true">https://forum.qt.io/post/560937</guid><dc:creator><![CDATA[Mark81]]></dc:creator><pubDate>Sun, 10 Nov 2019 12:13:07 GMT</pubDate></item><item><title><![CDATA[Reply to QTableView: select row with a specific id on Sun, 10 Nov 2019 12:11:48 GMT]]></title><description><![CDATA[<p dir="auto">I don't see another way, apart from that you should break out once the row is found.</p>
]]></description><link>https://forum.qt.io/post/560936</link><guid isPermaLink="true">https://forum.qt.io/post/560936</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 10 Nov 2019 12:11:48 GMT</pubDate></item></channel></rss>