PDA

View Full Version : [Solved] How to edit mainwindow.ui to add submenus



te777
25th July 2016, 09:03
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.



<widget class="QMenu" name="menuComplete_Analysis">
<property name="title">
<string>Complete Analysis</string>
</property>

<addmenu name="menuPowerball"/>

<addaction name="actionPowerball_numbers"/>
<addaction name="actionPowerball_power_ball"/>
<addaction name="actionPowerball_Numbers_Ranks"/>
<addaction name="actionPowerball_Numbers_Ranks_Average"/>
<addaction name="separator"/>
<addaction name="actionPowerball_Matching_Combinations"/>
<addaction name="actionPowerball_Enter_numbers_to_check_matches"/>
<addaction name="actionPowerball_Check_Matches_History"/>
<addaction name="separator"/>
<addaction name="actionPowerball_Find_Best_Combinations_2"/>
<addaction name="actionPowerball_Find_Best_Combinations_3"/>
<addaction name="actionPowerball_FInd_Best_Combinations_3"/>
<addaction name="actionPowerball_Find_Best_Combinations_4"/>
<addaction name="actionPowerball_Combinations_All"/>
<addaction name="separator"/>
<addaction name="actionPowerball_Random_Numbers_Analysis"/>
<addaction name="actionPowerball_Random_Numbers_Analysis_2"/>

<addmenu name="menuMega_Millions"/>

<addaction name="actionMega_Millions_numbers"/>
<addaction name="actionMega_Millions_mega_ball"/>
<addaction name="actionMega_Millions_Numbers_Ranks"/>
<addaction name="actionMega_Millions_Numbers_Rank_Average"/>
<addaction name="separator"/>
<addaction name="actionMega_Millions_Matching_Combinations"/>
<addaction name="actionMega_Millions_Enter_numbers_to_check_matches"/>
<addaction name="actionMega_Millions_Check_Matches_History"/>
<addaction name="separator"/>
<addaction name="actionMega_Millions_Find_Best_Combinations_2"/>
<addaction name="actionMega_Millions_Find_Best_Combinstions_3"/>
<addaction name="actionMega_Millions_Find_Best_Combinations_3"/>
<addaction name="actionMega_Millions_Find_Best_Combinations_4"/>
<addaction name="actionMega_Millions_Combinations_All"/>
<addaction name="separator"/>
<addaction name="actionMega_Millions_Random_Numbers_Analysis"/>
<addaction name="actionMega_Millions_Random_Numbers_Analysis_2"/>

</widget>

anda_skoa
25th July 2016, 09:48
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,
_

te777
25th July 2016, 11:42
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.

anda_skoa
25th July 2016, 14:25
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,
_

te777
26th July 2016, 13:29
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:



<widget class="QMenu" name="menuComplete_Analysis">
<property name="title">
<string>Complete Analysis</string>
</property>
<widget class="QMenu" name="menuPowerball">
<property name="title">
<string>Powerball</string>
</property>
<addaction name="actionNumbers"/>
<addaction name="actionPower_ball"/>
<addaction name="actionNumbers_Ranks"/>
<addaction name="actionNumbers_Rank_Average"/>
<addaction name="separator"/>
<addaction name="actionMatching_Combinations"/>
<addaction name="actionBest_Combinations_average"/>
<addaction name="actionBest_Combinations_predict"/>
<addaction name="actionBest_Combinations_random"/>
<addaction name="actionBest_Combinations_offset"/>
<addaction name="actionCombinations_All"/>
<addaction name="separator"/>
<addaction name="actionCheck_Matches"/>
<addaction name="actionCheck_Matches_History"/>
<addaction name="separator"/>
<addaction name="actionRandom_Numbers_Analysis"/>
<addaction name="actionRandom_Numbers_Analysis_2"/>
</widget>
<widget class="QMenu" name="menuMega_Millions">
<property name="title">
<string>Mega Millions</string>
</property>
<addaction name="actionNumbers_2"/>
<addaction name="actionMega_ball"/>
<addaction name="actionNumbers_Ranks_2"/>
<addaction name="actionNumbers_Rank_Average_2"/>
<addaction name="separator"/>
<addaction name="actionMatching_Combinations_2"/>
<addaction name="actionBest_Combinations_average_2"/>
<addaction name="actionBest_Combinations_predict_2"/>
<addaction name="actionBest_Combinations_random_2"/>
<addaction name="actionBest_Combinations_offset_2"/>
<addaction name="actionCombinations_All_2"/>
<addaction name="separator"/>
<addaction name="actionCheck_Matches_2"/>
<addaction name="actionCheck_Matches_History_2"/>
<addaction name="separator"/>
<addaction name="actionRandom_Numbers_Analysis_3"/>
<addaction name="actionRandom_Numbers_Analysis_4"/>
</widget>
<addaction name="menuPowerball"/>
<addaction name="separator"/>
<addaction name="menuMega_Millions"/>
</widget>

anda_skoa
26th July 2016, 14:48
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



connect(ui->oldActionName, SIGNAL(triggered()), this, SLOT(slotForActionName()));

becomes


connect(ui->newActionName, SIGNAL(triggered()), this, SLOT(slotForActionName()));

No need to change anything other than the first argument of the connect call.



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.



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?



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