<?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[[SOLVED] Using two different QTableWidgets in the same window. Focus and selection.]]></title><description><![CDATA[<p dir="auto">Good morning everybody;</p>
<p dir="auto">I have two different QTableWidgets in the same window, but sharing the data (although this doesn't matter). It's like having two ways of displaying the data.</p>
<p dir="auto">What I pursue is that, when I click to select one item in one table, the other one shows focused and selected the corresponding item. I success to do it 'one way', but not in both ways. So these are my questions:</p>
<ol>
<li>Is there anything to check if a QTableWidget is focused, something like ui-&gt;tableWidget-&gt;isFocused()?<br />
(I've try isActive(), isItemSelected(selectedItem),... without success). I want this because I'm using signals/slots to trigger this everytime the item selection changes in any of the tables:</li>
</ol>
<p dir="auto">@<br />
void Class::posChanged<br />
{<br />
if ( tableA -&gt; isFocused ( ) == true )<br />
tableB -&gt; setCurrentCell ( );</p>
<pre><code> if ( tableB -&gt; isFocused ( ) == true )
        tableA -&gt; setCurrentCell ( );
</code></pre>
<p dir="auto">}<br />
@</p>
<ol start="2">
<li>
<p dir="auto">Is there any way to keep the default blue selected background when the table isn't focused? I mean, if I focus on one of the tables, the focused table shows the selection with the normal blue background, but the not focused table turns the blue background into grey. I want to have both with the blue background (and avoid using setStyleSheet)</p>
</li>
<li>
<p dir="auto">In one of the tables, because of the number of rows, I have scroll bars. When I select an item in the other, in this table the corresponding selection is always at the bottom of the view, it doesn't show in the middle of the view area. Can the selected row of a table be forced to be in the middle of the view area?</p>
</li>
</ol>
<p dir="auto">Thank you in advance.</p>
<p dir="auto">Edit: Maybe the only solution to get 1) working is split into two different slots for the differents tables...?</p>
]]></description><link>https://forum.qt.io/topic/46962/solved-using-two-different-qtablewidgets-in-the-same-window-focus-and-selection</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 22:15:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/46962.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Oct 2014 09:28:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Using two different QTableWidgets in the same window. Focus and selection. on Wed, 15 Oct 2014 13:14:04 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your help.</p>
<p dir="auto">Everything is working.</p>
<p dir="auto">Even not being the cleanest way, the invertedRow method is perfect, because I'm making the table only once in a for loop, so it's not that dirty...</p>
<p dir="auto">Best.</p>
]]></description><link>https://forum.qt.io/post/247638</link><guid isPermaLink="true">https://forum.qt.io/post/247638</guid><dc:creator><![CDATA[pepita]]></dc:creator><pubDate>Wed, 15 Oct 2014 13:14:04 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Using two different QTableWidgets in the same window. Focus and selection. on Wed, 15 Oct 2014 10:55:17 GMT]]></title><description><![CDATA[<p dir="auto">bq. (...) so the bottom row is 1.</p>
<p dir="auto">In c+++ the more natural way is to start indexing from 0.</p>
<p dir="auto">So basically you want to invert the row index. That's easy. Make a method like this:<br />
@<br />
int invertedRow(int row) { return tableWidget-&gt;rowCount() - row -1; }<br />
@<br />
And use it whenever you need to pass a row index somewhere.</p>
<p dir="auto">Another, more encapsulated, way would be to inherit QTableWidget and reimplement all the methods that take row index as a parameter and call the base implementation with this inverted index. That's more work but a cleaner use afterwards. Your call.</p>
]]></description><link>https://forum.qt.io/post/247627</link><guid isPermaLink="true">https://forum.qt.io/post/247627</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Wed, 15 Oct 2014 10:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Using two different QTableWidgets in the same window. Focus and selection. on Wed, 15 Oct 2014 09:41:08 GMT]]></title><description><![CDATA[<p dir="auto">Hi again,</p>
<p dir="auto">I want to modify another thing from the QtableWidget, and i can't find how:</p>
<p dir="auto">I want to have the QtableWidget with the vertical header in descencending order, so the bottom row is 1. But not only change the labels, I really want to change the indexes of the vertical header (and the rows) to have something like a XY representation.</p>
<p dir="auto">This way, if I read XY coordinates from a file, say CSV, the table is representing the position in the XY graph...</p>
<p dir="auto">Thanks ;)</p>
]]></description><link>https://forum.qt.io/post/247617</link><guid isPermaLink="true">https://forum.qt.io/post/247617</guid><dc:creator><![CDATA[pepita]]></dc:creator><pubDate>Wed, 15 Oct 2014 09:41:08 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Using two different QTableWidgets in the same window. Focus and selection. on Mon, 13 Oct 2014 13:52:39 GMT]]></title><description><![CDATA[<p dir="auto">Thanks once again Chris.</p>
<p dir="auto">I didn't know sender method, it's what I was looking for when connecting several signals to the same slot...</p>
<p dir="auto">Best regards.</p>
]]></description><link>https://forum.qt.io/post/247298</link><guid isPermaLink="true">https://forum.qt.io/post/247298</guid><dc:creator><![CDATA[pepita]]></dc:creator><pubDate>Mon, 13 Oct 2014 13:52:39 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Using two different QTableWidgets in the same window. Focus and selection. on Mon, 13 Oct 2014 12:20:51 GMT]]></title><description><![CDATA[<ol>
<li>
<p dir="auto">The method is called hasFocus(). Also, inside the slot, you can check which widget sent the signal by calling sender() mehod.</p>
</li>
<li>
<p dir="auto">I know you said no styleSheet but it's actually the easiest way and can be made generic(ie. no hardcoded blue): @tableWidget-&gt;setStyleSheet("QTableView { selection-background-color: palette(Highlight); }");@<br />
Another way is by modifying the palette itself: <a class="plugin-mentions-user plugin-mentions-a" href="/user/auto">@<bdi>auto</bdi></a> palette = tableWidget-&gt;palette();<br />
auto brush = palette.brush(QPalette::Active, QPalette::Highlight);<br />
palette.setBrush(QPalette::Inactive, QPalette::Highlight, brush);<br />
tableWidget-&gt;setPalette(palette);@</p>
</li>
<li>
<p dir="auto">This should work: <a class="plugin-mentions-user plugin-mentions-a" href="/user/auto">@<bdi>auto</bdi></a> idx = tableWidget-&gt;model()-&gt;index(row, column);<br />
tableWidget-&gt;scrollTo(idx, QAbstractItemView::PositionAtCenter);<br />
@</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/247280</link><guid isPermaLink="true">https://forum.qt.io/post/247280</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Mon, 13 Oct 2014 12:20:51 GMT</pubDate></item></channel></rss>