QMenu* menu = new QMenu; QAction* action1 = menu->addAction("Action 1"); QAction* action2 = menu->addAction("Action 2"); // removing action1 when it is clicked QObject::connect(action1, &QAction::triggered, [menu, action1](){ menu->removeAction(action1); }); menu->exec(QCursor::pos());
QMenu* menu = new QMenu; QAction* action1 = menu->addAction("Action 1"); QAction* action2 = menu->addAction("Action 2"); QPushButton* button = new QPushButton("Remove Action 1"); QObject::connect(button, &QPushButton::clicked, [menu, action1](){ menu->removeAction(action1); }); menu->addAction(button); menu->exec(QCursor::pos());These examples are using the Qt library package.