Menus, Submenus, and Actions
Hello,
I have a menu called AWG which contains five submenus, each representing a specific instance of a general thing (a “PXâ€).
AWG
- PX1
- Enable
- Disable
- Reset
- Activate
- PX2
- Enable
- Disable
- Reset
- Activate
- PX3
- Enable
- Disable
- Reset
- Activate
- PX4
- Enable
- Disable
- Reset
- Activate
- PX5
- Enable
- Disable
- Reset
- Activate
Now each of these PX can be enabled, disabled, reset, and activated. Currently, I have four QActions representing those actions and I’ve added those actions to each PX submenu.
The question, how do I determine which submenu from which the action was triggered/clicked?
I need that information to apply the action to the right PX. (I can use the menu's text as a key to the right object.)
Any suggestions? BTW, I couldn’t find any obvious means of getting the “path†of an action. By path, I mean what chain of menus (if any), were clicked to trigger this action.
Thanks.
Re: Menus, Submenus, and Actions
I would just treat each sub menu as its own entity and let it have its own actions.
So there would be a direct mapping of action to sub menu.
Cheers,
_
Re: Menus, Submenus, and Actions
Quote:
Originally Posted by
anda_skoa
I would just treat each sub menu as its own entity and let it have its own actions.
So there would be a direct mapping of action to sub menu.
Cheers,
_
Thanks, I had thought of that, but discarded the idea because that would mean 20 Actions and 20 signals to respond to those actions. Also, I will be adding more PX and more functions that can be applied to a PX. I was hopeful that there was a more elegant solution.
Best Regards,
Re: Menus, Submenus, and Actions
Usually there are nice ways to encapsulate this, having one handler object for each PX.
You can also connect to the menu's signal if you don't want to connect to the individual actions.
Cheers,
_
Re: Menus, Submenus, and Actions
Quote:
Originally Posted by
anda_skoa
Usually there are nice ways to encapsulate this, having one handler object for each PX.
You can also connect to the menu's signal if you don't want to connect to the individual actions.
Cheers,
_
Sorry anda_skoa, but if you were suggesting a solution in there, I missed it :(
Also, there seems to be a misprint in the QT5 documentation. The documentation says that QMenu has a highlighted() signal -- but my compiler and the QT source code say otherwise. (I was going to trigger off the objectName() of the last menu highlighted.)
Re: Menus, Submenus, and Actions
Quote:
Originally Posted by
SpiceWeasel
Sorry anda_skoa, but if you were suggesting a solution in there, I missed it :(
I was offering an option to handle this more elegantly, i.e. handling each menu with a dedicated receiver/handler/controller object.
Without any knowledge about the concepts involved in your PX thingies it is hard to come up with any concrete advice.
Quote:
Originally Posted by
SpiceWeasel
Also, there seems to be a misprint in the QT5 documentation. The documentation says that QMenu has a highlighted() signal -- but my compiler and the QT source code say otherwise. (I was going to trigger off the objectName() of the last menu highlighted.)
http://doc.qt.io/qt-5/qmenu.html says it has "aboutToShow", "aboutToHide", "triggered" and "hovered" signals.
Cheers,
_
Re: Menus, Submenus, and Actions
Quote:
Originally Posted by
anda_skoa
Yes, it does, but it also says...
In addition, QMenu provides two signals, activated() and highlighted(), which signal the QAction that was triggered from the menu.
Re: Menus, Submenus, and Actions
Ah, indeed.
Since those are not links it is a good indication that these do not exists.
Must have been left over from an earlier version
Cheers,
_