Action still available in disabled menu via short cuts



  • Hi,

    I noticed that my actions in my QMenu are still available via the short cut even if the menu the actions are located in is disabled.

    Menu:
    File Edit Insert
    -quit -find -image

    So if set Insert to disabled I can access image via its short cut.

    My expectation would have been that if Insert is disabled all actions within Insert would be disabled as well. Is this not linked or is there a special setting I did not see to lock the children enable to the parent enable?


  • Moderators

    Usually you disable the actions directly. Disabling a menu only disables access to it from a parent menu or a button, not to the actions inside it.
    An action can be added to many menus, toolbars, widgets etc. at the same time. Disabling any of them should not disable the action.



  • I am not sure if this really makes sense. If I disable a menu I do it for a reason. I don't want the user to have access to the actions. Actually I cannot think of a situation where I want to disable the menu but not the functionality...


  • Moderators

    If you want to disable functionality disable the functionality (action).Menu is just a container. If you have the same action in a menu and on a toolbar and you want to disable it you disable the action, not the menu.
    What actually rarely makes sense is disabling a menu.



  • My menu Insert is only valid if there is a file opened with the app. As long as no file is opened I cannot insert something. You can find this kind of behavior in many programs e.g. open office.

    My hope was that disabling the menu would trigger a disable for all actions as well so that I do not have to do it manually.


  • Moderators

    Right, but, as I said - an action can be put in many containers simultaneously. It would be weird if disabling it disabled all the others so it doesn't do that.
    If you need that - quite easy. Just disable/enable the actions in the menu's changeEvent when the event is QEvent::EnabledChange.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.