PDA

View Full Version : Menus, Submenus, and Actions



SpiceWeasel
19th August 2015, 01:35
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.

anda_skoa
19th August 2015, 10:51
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,
_

SpiceWeasel
19th August 2015, 13:01
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,

anda_skoa
19th August 2015, 13:12
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,
_

SpiceWeasel
19th August 2015, 14:56
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.)

anda_skoa
19th August 2015, 16:18
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.



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,
_

SpiceWeasel
19th August 2015, 18:14
http://doc.qt.io/qt-5/qmenu.html says it has "aboutToShow", "aboutToHide", "triggered" and "hovered" signals.
_

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.

anda_skoa
19th August 2015, 18:29
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,
_