问题
I'm trying to implement Qt Menus customization, and I'm giving a feature to add same QAction
more than once in the same RMB context menu. But when I try to do:
myMenu->addAction( myAction );
myMenu->addAction( myAction );
Adding QAction
twice, only one instance of QAction
appear on the menu.
Why can't I have more than one instances of QAction
? Is there any trick to achieve this?
I was trying to clone/create a new action with all the propeties of previous action. But I don't know the way to get/extract a QActions
's SENDER
and MEMBER
properties.
回答1:
This is a deliberate decision. See the documentation about it:
A QWidget should only have one of each action and adding an action it already has will not cause the same action to be in the widget twice.
The reason is probably that either there has been no use case for this, or if any, it has not covered what the majority wanted.
Based on your comment that MS Outlook allows this and you are trying to mimic it... I would personally just take the approach of warning the user when they are trying to add the same action to the same menu again.
来源:https://stackoverflow.com/questions/24847841/how-can-i-add-more-than-one-qaction-to-same-qmenu