2
votes

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
Why would you do this in the first place?lpapp
as far as I remember from my most recent QT usage (about 2 years ago), QActions are a semantic action, so QT prevents you from doing this, because you wouldn't want multiple menu buttons to do exactly the same thing. you could create multiple actions for each button (but please first rethink your concept, it seems like you are trying to do something you don't really want to do there ;)), or maybe use something different from QAction (I don't know for sure, but I think there's an arbitrary QMenuItem class?).nonchip
+1 @FinalContest: It's very likely you're misunderstanding the meaning of QAction here, so try to explain what you're doing. How should your menu look like, what should the different buttons do, and which of them are the QActions you asked about?nonchip
@FinalContest Actually, I'm giving user a way to add as many menus and as manu times he wants to add to existing menu level...this idea is actually inspired by MS Outlook->tools->Customize->Rearrange Commands option. They too allow having same action more than once in the menu. I was just trying to implement that... Or MAYBE, I shouldn't allow this at first place? I should warn the user that this action has already been added!?Maverick33

1 Answers

1
votes

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.