Results 1 to 8 of 8

Thread: Menus, Submenus, and Actions

  1. #1
    Join Date
    Apr 2014
    Posts
    34
    Thanks
    14
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Question 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
    1. PX1
      1. Enable
      2. Disable
      3. Reset
      4. Activate
    2. PX2
      1. Enable
      2. Disable
      3. Reset
      4. Activate
    3. PX3
      1. Enable
      2. Disable
      3. Reset
      4. Activate
    4. PX4
      1. Enable
      2. Disable
      3. Reset
      4. Activate
    5. PX5
      1. Enable
      2. Disable
      3. Reset
      4. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

  3. #3
    Join Date
    Apr 2014
    Posts
    34
    Thanks
    14
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Menus, Submenus, and Actions

    Quote Originally Posted by anda_skoa View Post
    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,

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

  5. #5
    Join Date
    Apr 2014
    Posts
    34
    Thanks
    14
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Menus, Submenus, and Actions

    Quote Originally Posted by anda_skoa View Post
    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.)

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Menus, Submenus, and Actions

    Quote Originally Posted by SpiceWeasel View Post
    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 View Post
    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,
    _

  7. #7
    Join Date
    Apr 2014
    Posts
    34
    Thanks
    14
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Menus, Submenus, and Actions

    Quote Originally Posted by anda_skoa View Post
    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

Similar Threads

  1. menu tearoffs/submenus not using stylesheet
    By ntp in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2010, 17:51
  2. Context Menus
    By rodlbr in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 17:30
  3. Accessible menus
    By NickPoole in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2009, 10:30
  4. Chevron Menus
    By TehriBoy in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2008, 17:28
  5. Why are actions limited to menus and toolbars?
    By Paul Drummond in forum Qt Programming
    Replies: 16
    Last Post: 3rd March 2006, 13:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.