Qt 6.11 is out! See what's new in the release
blog
Another Context menu in Qt Main window
-
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 ??
-
Oh, i figured it,
actually i had not set the Defaultcustommenu policy to customcontextmenu policy