<?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[Another Context menu in Qt Main window]]></title><description><![CDATA[<p dir="auto">i have two QListWidget's in my main window , one is named "ui_sketch_textbox" , other is name "elem_list" ,</p>
<p dir="auto">I have custom context menu for ui_sketch_textbox  , this context menu is working and this is the code for it.</p>
<pre><code>void MainWindow::on_ui_sketch_textbox_customContextMenuRequested(const QPoint&amp; pos)
{
    QMenu* pMenu = new QMenu(this);

   
    QAction* pChildren = new QAction(tr("Children "), this);
    QAction* pDescendants = new QAction(tr("Descendants "), this);
    QAction* pSubtree = new QAction(tr("Subtree "), this);
    QAction* pScan_Descendants = new QAction(tr("List Descendants using Treewalk "), this);
    QAction* pScan_Ancestors = new QAction(tr("List Ancestors using Treewalk "), this);

  
    pMenu-&gt;addAction(pChildren);
    pMenu-&gt;addAction(pDescendants);
    pMenu-&gt;addAction(pSubtree);
    pMenu-&gt;addAction(pScan_Descendants);
    pMenu-&gt;addAction(pScan_Ancestors);

   

    connect(pScan_Ancestors, SIGNAL(triggered()), this, SLOT(ScanAncestors()));
    connect(pScan_Descendants, SIGNAL(triggered()), this, SLOT(ScanDescendants()));
    connect(pChildren, SIGNAL(triggered()), this, SLOT(ChildrenLogic()));
    connect(pDescendants, SIGNAL(triggered()), this, SLOT(DescendantsLogic()));
    connect(pSubtree, SIGNAL(triggered()), this, SLOT(SubtreeLogic()));
   

    pMenu-&gt;exec(cursor().pos());

    //Release the memory
    QList&lt;QAction*&gt; list = pMenu-&gt;actions();
    foreach(QAction * pAction, list) delete pAction;

    delete pMenu;

}
</code></pre>
<p dir="auto">but i am trying to create another context menu for QListWidget named "elem_list" this is not working/doesnt show up when i right click</p>
<p dir="auto">this is the code for it</p>
<pre><code>
void MainWindow::on_elem_list_customContextMenuRequested(const QPoint&amp; pos)
{
    QMenu* sMenu = new QMenu(this);

    QAction* showTree = new QAction(tr("Show Tree "), this);

    sMenu-&gt;addAction(showTree);

    sMenu-&gt;exec(cursor().pos());

    delete sMenu;

}
</code></pre>
<p dir="auto">how do i get the second context menu working ??</p>
]]></description><link>https://forum.qt.io/topic/114488/another-context-menu-in-qt-main-window</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 02:18:01 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/114488.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 May 2020 22:45:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Another Context menu in Qt Main window on Tue, 05 May 2020 23:04:01 GMT]]></title><description><![CDATA[<p dir="auto">Oh, i figured it,</p>
<p dir="auto">actually i had not set the Defaultcustommenu policy to customcontextmenu policy</p>
]]></description><link>https://forum.qt.io/post/592864</link><guid isPermaLink="true">https://forum.qt.io/post/592864</guid><dc:creator><![CDATA[Mr-Workalot]]></dc:creator><pubDate>Tue, 05 May 2020 23:04:01 GMT</pubDate></item></channel></rss>