例如,我有一个菜单,并在其中添加一个动作。过了一段时间后,我想用新的动作取代动作,因为它变得无效。怎么实现呢?
QMenu* menu = new QMenu(this);
...
QAction* action = menu->addAction("text");
...
QAction* newAction = new QAction(menu);
// how to replace?
答案 0 :(得分:3)
// To replace action with yetAnotherAction:
menu->insertAction(action,yetAnotherAction);
menu->removeAction(action);