Reputation: 3130
I need to remove actions from a QMenu
, but I need to add them later.
The problem is that whan I re-add them, they dont appear (probably because the actions are deleted when I remove them from the Menu).
How can I do this?
Note that hiding/disabling, etc is not suitable for me, I really need to remove them
Upvotes: 2
Views: 4829
Reputation: 12898
You don't say precisely how you create/add/remove the actions from the QMenu
so I can't comment on what you're currently doing, but... you should be able to create/manage some of the actions yourself and then use the QWidget::addAction(QAction *)
overload -- it doesn't assume ownership of the QAction
passed as a parameter.
QMenu menu;
QAction action_I_Want_to_manage("Save...");
menu.addAction("File...");
menu.addAction(&action_I_Want_to_manage);
menu.exec(QCursor::pos());
/*
* Remove the action temporarily...
*/
menu.removeAction(&action_I_Want_to_manage);
menu.exec(QCursor::pos());
/*
* ...stick it back in.
*/
menu.addAction(&action_I_Want_to_manage);
menu.exec(QCursor::pos());
Upvotes: 3