2

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.

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Maverick33
  • 337
  • 3
  • 15
  • 2
    Why would you do this in the first place? – László Papp Jul 20 '14 at 06:26
  • 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 Jul 20 '14 at 06:30
  • +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 Jul 20 '14 at 06:31
  • @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 Jul 20 '14 at 06:54

1 Answers1

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135