<?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[Context menu on QTreeView item?]]></title><description><![CDATA[<p dir="auto">I have a QTreeView of a heirarchy of items, and it works fine. I've set up a context menu on that tree view, and that gets me a QPoint when I right-click on an item and select an action. How do I get the item I've right-clicked on from that QPoint?</p>
<p dir="auto">Here's what I'm aiming for:</p>
<pre><code>Item 1
Item 2
    |____ Item 2a &lt;---- Right-click here
    |____ Item 2b
Item 3
</code></pre>
<p dir="auto">I want to be able to right-click on Item 2a here, select "delete" from the context menu, and use the resulting QPoint to delete Item 2a and its associated data from the treeview. How do I go about that?</p>
]]></description><link>https://forum.qt.io/topic/153289/context-menu-on-qtreeview-item</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 15:41:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/153289.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Dec 2023 02:19:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Context menu on QTreeView item? on Sun, 31 Dec 2023 02:52:58 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, folks. That worked fine.</p>
]]></description><link>https://forum.qt.io/post/784692</link><guid isPermaLink="true">https://forum.qt.io/post/784692</guid><dc:creator><![CDATA[rjmx]]></dc:creator><pubDate>Sun, 31 Dec 2023 02:52:58 GMT</pubDate></item><item><title><![CDATA[Reply to Context menu on QTreeView item? on Wed, 27 Dec 2023 14:17:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> The link was to QAIV::indexAt(). Just the link text was wrong as I first was on the item widgets instead views.</p>
<p dir="auto">QAIV = QAbstractItemView</p>
]]></description><link>https://forum.qt.io/post/784382</link><guid isPermaLink="true">https://forum.qt.io/post/784382</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Wed, 27 Dec 2023 14:17:26 GMT</pubDate></item><item><title><![CDATA[Reply to Context menu on QTreeView item? on Wed, 27 Dec 2023 14:00:48 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/784348">Context menu on QTreeView item?</a>:<br />
QAIV  ???<br />
itemAt() doesn't exist for QTreeView.<br />
It's QTreeView::indexAt()</p>
<p dir="auto">But in context menu, you receive a signal in a slot with no  explicit mouse location.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rjmx">@<bdi>rjmx</bdi></a><br />
You can retreive the selected cell, here some code of mine:</p>
<pre><code>void BookmarksManager::contextMenuAction(QAction *action)
{
	QModelIndex selectedIndex;

	bool hasSelection=!sBookmarksDialog-&gt;treeView()-&gt;selectionModel()-&gt;selectedRows().isEmpty();

	if(hasSelection)
	{
		selectedIndex=sBookmarksDialog-&gt;treeView()-&gt;selectionModel()-&gt;selectedRows().first();
		
		if(action-&gt;objectName()==Menu_Delete)
		{
		// delete item here
		}
		else if(...)
		...
	}
</code></pre>
]]></description><link>https://forum.qt.io/post/784380</link><guid isPermaLink="true">https://forum.qt.io/post/784380</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Wed, 27 Dec 2023 14:00:48 GMT</pubDate></item><item><title><![CDATA[Reply to Context menu on QTreeView item? on Wed, 27 Dec 2023 14:13:25 GMT]]></title><description><![CDATA[<p dir="auto">You can use <a href="https://doc.qt.io/qt-6/qabstractitemview.html#indexAt" target="_blank" rel="noopener noreferrer nofollow ugc">QAIV::indexAt()</a>.</p>
]]></description><link>https://forum.qt.io/post/784348</link><guid isPermaLink="true">https://forum.qt.io/post/784348</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Wed, 27 Dec 2023 14:13:25 GMT</pubDate></item></channel></rss>