<?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[mousePressedEvent handler for QTableView]]></title><description><![CDATA[<p dir="auto">I want to handle RMB press events on the viewport and pop a menu when this is done.</p>
<p dir="auto">When a menu item is chosen, it should apply to all selected rows in the table view.</p>
<ol>
<li>
<p dir="auto">I think I need to sub-class QTableView to achieve this?  Or is there a "neat" way to handle this in the owning widget?</p>
</li>
<li>
<p dir="auto">I want to enable some menu items only if the mouse is over a row of the table (rather than a blank area) - how do I do that?</p>
</li>
<li>
<p dir="auto">I don't wish to react to RMB on the header, but I think I can just check horizontalHeader()-&gt;underMouse() - is that right?</p>
</li>
</ol>
<p dir="auto">Thanks<br />
David</p>
]]></description><link>https://forum.qt.io/topic/139538/mousepressedevent-handler-for-qtableview</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 06:13:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139538.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Sep 2022 10:08:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to mousePressedEvent handler for QTableView on Sat, 24 Sep 2022 10:23:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a></p>
<ol>
<li>
<p dir="auto">You can usually achieve event handling without subclassing if you go via <code>eventFilter()</code>.  But as you add functionality to a <code>QTableView</code> like this it becomes nicer if sub-classed.  I would (think ) would be subclassing to override <code>contextMenuEvent()</code>.</p>
</li>
<li>
<p dir="auto"><code>QTableWidget</code> has an <code>itemAt()</code>.  For <code>QTableView</code> what about <code>rowAt(int y)</code> or <code>indexAt(const QPoint &amp;pos)</code>?  Check what coordinates the mouse position returns, may have to be mapped to table view, not sure.</p>
</li>
<li>
<p dir="auto">Probably yes, or it may come out in the wash from #2.</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/730027</link><guid isPermaLink="true">https://forum.qt.io/post/730027</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 24 Sep 2022 10:23:28 GMT</pubDate></item><item><title><![CDATA[Reply to mousePressedEvent handler for QTableView on Wed, 28 Sep 2022 02:33:32 GMT]]></title><description><![CDATA[<pre><code>void StackingDlg::on_tableView_customContextMenuRequested(const QPoint&amp; pos)
</code></pre>
<p dir="auto">is what I used - thanks</p>
]]></description><link>https://forum.qt.io/post/730432</link><guid isPermaLink="true">https://forum.qt.io/post/730432</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Wed, 28 Sep 2022 02:33:32 GMT</pubDate></item><item><title><![CDATA[Reply to mousePressedEvent handler for QTableView on Tue, 27 Sep 2022 16:24:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a><br />
In addition to being able to subclass and override <code>contextMenuEvent()</code>, there is <em>signal</em> <a href="https://doc.qt.io/qt-6/qwidget.html#customContextMenuRequested" target="_blank" rel="noopener noreferrer nofollow ugc">void QWidget::customContextMenuRequested(const QPoint &amp;pos)</a>, which does not require subclassing.  You choose between event versus signal via <a href="https://doc.qt.io/qt-6/qwidget.html#contextMenuPolicy-prop" target="_blank" rel="noopener noreferrer nofollow ugc">setContextMenuPolicy(Qt::ContextMenuPolicy policy)</a> with <a href="https://doc.qt.io/qt-6/qt.html#ContextMenuPolicy-enum" target="_blank" rel="noopener noreferrer nofollow ugc">enum Qt::ContextMenuPolicy</a>.</p>
]]></description><link>https://forum.qt.io/post/730377</link><guid isPermaLink="true">https://forum.qt.io/post/730377</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 27 Sep 2022 16:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to mousePressedEvent handler for QTableView on Tue, 27 Sep 2022 16:15:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/730027">mousePressedEvent handler for QTableView</a>:</p>
<blockquote>
<p dir="auto">contextMenuEvent()</p>
</blockquote>
<p dir="auto">That was what was needed!</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/post/730375</link><guid isPermaLink="true">https://forum.qt.io/post/730375</guid><dc:creator><![CDATA[Perdrix]]></dc:creator><pubDate>Tue, 27 Sep 2022 16:15:06 GMT</pubDate></item><item><title><![CDATA[Reply to mousePressedEvent handler for QTableView on Sat, 24 Sep 2022 10:23:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/perdrix">@<bdi>Perdrix</bdi></a></p>
<ol>
<li>
<p dir="auto">You can usually achieve event handling without subclassing if you go via <code>eventFilter()</code>.  But as you add functionality to a <code>QTableView</code> like this it becomes nicer if sub-classed.  I would (think ) would be subclassing to override <code>contextMenuEvent()</code>.</p>
</li>
<li>
<p dir="auto"><code>QTableWidget</code> has an <code>itemAt()</code>.  For <code>QTableView</code> what about <code>rowAt(int y)</code> or <code>indexAt(const QPoint &amp;pos)</code>?  Check what coordinates the mouse position returns, may have to be mapped to table view, not sure.</p>
</li>
<li>
<p dir="auto">Probably yes, or it may come out in the wash from #2.</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/730027</link><guid isPermaLink="true">https://forum.qt.io/post/730027</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 24 Sep 2022 10:23:28 GMT</pubDate></item></channel></rss>