@mrjj said in QMenu & QAction get sender button/widget?:
Hi
Why do you need to know the parent?
QAction can be shared so the same function can be activated from
multiple sources. But normally action does the same regardless from where is was triggered.
I need to adjust action command parameters depending on the parent widget.
I tried action->parentWidget() but it did not return anything I could use .
Esentially I can have action that does A+B, and if the action is in global widget it would do just that, but if its in local widget then I will need localA + localB... more or less... thus the need to have a way to knowing parent widget while sending command to work.
@Chris-Kawa said in QMenu & QAction get sender button/widget?:
Instead of starting with the action you can connect to the menu's triggered signal. In the slot sender() will give you the menu and you can go up the parents with parentWidget() to find the toolbar if you need.
Hmmmmm that looks very tempting!!! Will give it a go thanks!
I was about to write my own action system to handle my needs but perhaps with Chris Kawa reply I can utilize native qt ones ! Thanks!
BRB testing.
Ok so this gets me half way there. I can now do quite a bit nice stuff with menu & actions, like changing menu default action to do something else based on action clicked and all that - yay !
But... how do I find out that menu parent - QToolbar or QToolButton? Is there a path down from there?
And it looks like the toolButton has thesame triggered signal... hmmmm
yep this is beautifull, it propagates all the way to toolButton where I can do what I want with the action and its data.
Amazing, whoever designed that system is my hero.