Results 1 to 6 of 6

Thread: [Solved] How to edit mainwindow.ui to add submenus

  1. #1
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default [Solved] How to edit mainwindow.ui to add submenus

    I have an app that has too many items in one of the menu choices. I need to create 2 submenus from that menu choice and split action items between the 2 submenus. I'm trying to edit the mainwindow.ui in Notepad but I don't know the syntax needed to create submenus, then to add the action items to the submenus. I want to move all the Powerball items to a Powerball submenu, and all the Mega Millions items to a Mega Millions submenu. Here's what I have. Any replies would be welcome.

    I hope the subject matter of the application doesn't turn off possible repliers. It's a free application available on the web that I've developed in my spare time. It is not a commercial application.


    Qt Code:
    1. <widget class="QMenu" name="menuComplete_Analysis">
    2. <property name="title">
    3. <string>Complete Analysis</string>
    4. </property>
    5.  
    6. <addmenu name="menuPowerball"/>
    7.  
    8. <addaction name="actionPowerball_numbers"/>
    9. <addaction name="actionPowerball_power_ball"/>
    10. <addaction name="actionPowerball_Numbers_Ranks"/>
    11. <addaction name="actionPowerball_Numbers_Ranks_Average"/>
    12. <addaction name="separator"/>
    13. <addaction name="actionPowerball_Matching_Combinations"/>
    14. <addaction name="actionPowerball_Enter_numbers_to_check_matches"/>
    15. <addaction name="actionPowerball_Check_Matches_History"/>
    16. <addaction name="separator"/>
    17. <addaction name="actionPowerball_Find_Best_Combinations_2"/>
    18. <addaction name="actionPowerball_Find_Best_Combinations_3"/>
    19. <addaction name="actionPowerball_FInd_Best_Combinations_3"/>
    20. <addaction name="actionPowerball_Find_Best_Combinations_4"/>
    21. <addaction name="actionPowerball_Combinations_All"/>
    22. <addaction name="separator"/>
    23. <addaction name="actionPowerball_Random_Numbers_Analysis"/>
    24. <addaction name="actionPowerball_Random_Numbers_Analysis_2"/>
    25.  
    26. <addmenu name="menuMega_Millions"/>
    27.  
    28. <addaction name="actionMega_Millions_numbers"/>
    29. <addaction name="actionMega_Millions_mega_ball"/>
    30. <addaction name="actionMega_Millions_Numbers_Ranks"/>
    31. <addaction name="actionMega_Millions_Numbers_Rank_Average"/>
    32. <addaction name="separator"/>
    33. <addaction name="actionMega_Millions_Matching_Combinations"/>
    34. <addaction name="actionMega_Millions_Enter_numbers_to_check_matches"/>
    35. <addaction name="actionMega_Millions_Check_Matches_History"/>
    36. <addaction name="separator"/>
    37. <addaction name="actionMega_Millions_Find_Best_Combinations_2"/>
    38. <addaction name="actionMega_Millions_Find_Best_Combinstions_3"/>
    39. <addaction name="actionMega_Millions_Find_Best_Combinations_3"/>
    40. <addaction name="actionMega_Millions_Find_Best_Combinations_4"/>
    41. <addaction name="actionMega_Millions_Combinations_All"/>
    42. <addaction name="separator"/>
    43. <addaction name="actionMega_Millions_Random_Numbers_Analysis"/>
    44. <addaction name="actionMega_Millions_Random_Numbers_Analysis_2"/>
    45.  
    46. </widget>
    To copy to clipboard, switch view to plain text mode 
    Last edited by te777; 25th July 2016 at 11:43.

  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: How to edit mainwindow.ui to add submenus

    Where did you find the information that addmenu is a valid tag?
    In the UIC source code?

    The weird thing in your example is that it is an empty tag and does not include the menu's actions.

    From the XML's structure I would assume that the actions are added to the "Complete Analysis" menu.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to edit mainwindow.ui to add submenus

    Yes the "addmenu" tag was just there as a dummy tag to show what I was trying to do. I solved the problem by creating the submenus in Designer, then copying all the code from the old slots to the new slots. I was hoping to just edit the mainwindow.ui without having create new slots and copy the code. But it's fixed now.

  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: How to edit mainwindow.ui to add submenus

    Modifying the file manually would have been an option, you would just have had to look how the correct syntax looks like by creating a simple example.

    My guess would have been that a sub menu is a sub <widget> element.

    I don't understand what you meant with "coping the code to the new slots".
    The slots are independent of where the actions appear in the menu, so there is no need for new slots or copying any code.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to edit mainwindow.ui to add submenus

    I had renamed the menu items in the submenus to get rid of the Powerball and Megamillions names for the submenu items. As you can see from the syntax below I think I wouldn't have gotten it right by just editing the mainwindow.ui. Plus the code to copy was just procedure calls to other classes so it wasn' that much trouble to copy. And now my mainwindow.cpp is much easier to read since I had created the new submenu items in sequential order, so my new slots were in that order too. It's better now and easier to manage, with a better look and fell for the user with the new submenu items. So I now have:

    Qt Code:
    1. <widget class="QMenu" name="menuComplete_Analysis">
    2. <property name="title">
    3. <string>Complete Analysis</string>
    4. </property>
    5. <widget class="QMenu" name="menuPowerball">
    6. <property name="title">
    7. <string>Powerball</string>
    8. </property>
    9. <addaction name="actionNumbers"/>
    10. <addaction name="actionPower_ball"/>
    11. <addaction name="actionNumbers_Ranks"/>
    12. <addaction name="actionNumbers_Rank_Average"/>
    13. <addaction name="separator"/>
    14. <addaction name="actionMatching_Combinations"/>
    15. <addaction name="actionBest_Combinations_average"/>
    16. <addaction name="actionBest_Combinations_predict"/>
    17. <addaction name="actionBest_Combinations_random"/>
    18. <addaction name="actionBest_Combinations_offset"/>
    19. <addaction name="actionCombinations_All"/>
    20. <addaction name="separator"/>
    21. <addaction name="actionCheck_Matches"/>
    22. <addaction name="actionCheck_Matches_History"/>
    23. <addaction name="separator"/>
    24. <addaction name="actionRandom_Numbers_Analysis"/>
    25. <addaction name="actionRandom_Numbers_Analysis_2"/>
    26. </widget>
    27. <widget class="QMenu" name="menuMega_Millions">
    28. <property name="title">
    29. <string>Mega Millions</string>
    30. </property>
    31. <addaction name="actionNumbers_2"/>
    32. <addaction name="actionMega_ball"/>
    33. <addaction name="actionNumbers_Ranks_2"/>
    34. <addaction name="actionNumbers_Rank_Average_2"/>
    35. <addaction name="separator"/>
    36. <addaction name="actionMatching_Combinations_2"/>
    37. <addaction name="actionBest_Combinations_average_2"/>
    38. <addaction name="actionBest_Combinations_predict_2"/>
    39. <addaction name="actionBest_Combinations_random_2"/>
    40. <addaction name="actionBest_Combinations_offset_2"/>
    41. <addaction name="actionCombinations_All_2"/>
    42. <addaction name="separator"/>
    43. <addaction name="actionCheck_Matches_2"/>
    44. <addaction name="actionCheck_Matches_History_2"/>
    45. <addaction name="separator"/>
    46. <addaction name="actionRandom_Numbers_Analysis_3"/>
    47. <addaction name="actionRandom_Numbers_Analysis_4"/>
    48. </widget>
    49. <addaction name="menuPowerball"/>
    50. <addaction name="separator"/>
    51. <addaction name="menuMega_Millions"/>
    52. </widget>
    To copy to clipboard, switch view to plain text mode 
    Last edited by te777; 26th July 2016 at 14:08.

  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: How to edit mainwindow.ui to add submenus

    Quote Originally Posted by te777 View Post
    I had renamed the menu items in the submenus to get rid of the Powerball and Megamillions names for the submenu items.
    Ok, but that only requires to change the connects, not the slots in any way

    Qt Code:
    1. connect(ui->oldActionName, SIGNAL(triggered()), this, SLOT(slotForActionName()));
    To copy to clipboard, switch view to plain text mode 
    becomes
    Qt Code:
    1. connect(ui->newActionName, SIGNAL(triggered()), this, SLOT(slotForActionName()));
    To copy to clipboard, switch view to plain text mode 
    No need to change anything other than the first argument of the connect call.

    Quote Originally Posted by te777 View Post
    As you can see from the syntax below I think I wouldn't have gotten it right by just editing the mainwindow.ui.
    Ah, as I expected the sub menu is just a child widget.

    Quote Originally Posted by te777 View Post
    Plus the code to copy was just procedure calls to other classes so it wasn' that much trouble to copy.
    Sure, but why copy at all?

    Quote Originally Posted by te777 View Post
    And now my mainwindow.cpp is much easier to read since I had created the new submenu items in sequential order, so my new slots were in that order too.
    The order of slots is independent of the order of actions.
    They don't even need to be on the same object.

    Cheers,
    _

Similar Threads

  1. Menus, Submenus, and Actions
    By SpiceWeasel in forum Qt Programming
    Replies: 7
    Last Post: 19th August 2015, 17:29
  2. Edit a QListWidget from a MainWindow Component
    By xXTheAwesomerXx in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2015, 11:36
  3. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  4. Replies: 2
    Last Post: 4th April 2013, 06:36
  5. menu tearoffs/submenus not using stylesheet
    By ntp in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2010, 16:51

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.