Maverick33
Maverick33

Reputation: 337

How can I add more than one QAction to same QMenu?

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.

Upvotes: 2

Views: 1422

Answers (1)

László Papp
László Papp

Reputation: 53155

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.

Upvotes: 2

Related Questions