0

I have a QMenu and actions added to it. Works fine. Assume it does have menu called "Paste here" in it.

So now I have 3 buttons, I assign this same menu to three buttons:

btnNum1->setMenu(MyMenu);
btnNum2->setMenu(MyMenu);
btnNum3->setMenu(MyMenu);

Now in the triggered slot, when I do:

qDebug() << QObject::sender();

I get the QAction which is the submenu item, I want to know which button invoked the menu which then user clicked on a menu item and triggered the slot. I need to know is it menu loaded in btnNum1 or btnNum2 or btnNum3.

Is it even possible?

  • I don't think so. You'll probably need to create three different menu objects if you want to be able to distinguish them. – Jeremy Friesner Oct 21 '15 at 02:43
  • 1
    Take a look at the right answer in [this](http://stackoverflow.com/questions/5153157/passing-an-argument-to-a-slot) question. – folibis Oct 21 '15 at 04:48
  • As @folibis links, you can solve this easily via ``QSignalMapper`` – Sebastian Lange Oct 21 '15 at 05:17
  • @folibis, how to you define same action for two different buttons with same menu? I can't see how with SignalMapper –  Oct 21 '15 at 13:24
  • yes, you are right @JohnMcKean. You need to track what button cause to menu popup, not action. So maybe you have to redefine `QPushButton` or `QMenu` to set suitable pointer to button while button pressing. And so you will be able to get this pointer from `QAction->menu()->myPointerToButton` – folibis Oct 21 '15 at 22:49

0 Answers0