Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Another Context menu in Qt Main window
Qt 6.11 is out! See what's new in the release blog

Another Context menu in Qt Main window

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 269 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr-Workalot
    wrote on last edited by
    #1

    i have two QListWidget's in my main window , one is named "ui_sketch_textbox" , other is name "elem_list" ,

    I have custom context menu for ui_sketch_textbox , this context menu is working and this is the code for it.

    void MainWindow::on_ui_sketch_textbox_customContextMenuRequested(const QPoint& 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->addAction(pChildren);
        pMenu->addAction(pDescendants);
        pMenu->addAction(pSubtree);
        pMenu->addAction(pScan_Descendants);
        pMenu->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->exec(cursor().pos());
    
        //Release the memory
        QList<QAction*> list = pMenu->actions();
        foreach(QAction * pAction, list) delete pAction;
    
        delete pMenu;
    
    }
    

    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

    this is the code for it

    
    void MainWindow::on_elem_list_customContextMenuRequested(const QPoint& pos)
    {
        QMenu* sMenu = new QMenu(this);
    
        QAction* showTree = new QAction(tr("Show Tree "), this);
    
        sMenu->addAction(showTree);
    
        sMenu->exec(cursor().pos());
    
        delete sMenu;
    
    }
    

    how do i get the second context menu working ??

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mr-Workalot
      wrote on last edited by
      #2

      Oh, i figured it,

      actually i had not set the Defaultcustommenu policy to customcontextmenu policy

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved