Hi There,
I’m wanting to add sub menus to a ComboBox.
I’ve found out how to do this to a PopupMenu, which is what’s inside a ComboBox.
There’s this little nugget in ComboBox:
/** Returns the PopupMenu object associated with the ComboBox.
Can be useful for adding sub-menus to the ComboBox standard PopupMenu
*/
PopupMenu* getRootMenu() { return ¤tMenu; }
But nothing further that I can find.
A combo box has addItem which can only add a PopupMenu item.
There doesn’t seem to be a way to add a subMenu.
Do I create the popup menus and add them into the combo box?
Thank you!
Look up PopupMenu. That’s the object you can add items and sub-menus to.
yes I saw that, but how do I set the combobox to use the popupo menu?
How about like this?
PopupMenu subMenu;
subMenu.addItem(id, “Sub Menu Item Name”);
mainMenu.getRootMenu()->addSubMenu(“Sub Menu Title”, subMenu);.
Yeah that’s how to add sub menus to a pop up menu.
How do you add the pop up menu to a combo box?
Hi @nigelstanford,
For doing that, personally I add menu item with name owning a special separator like that:
“menu1/submenu2”
“menu1/submenu2”
“menu2/submenu1”
“menu2/submenu2”
“menu2/submenu2/item1”
“menu2/submenu2/item2”
Then I create a new TreeStructuredComboBox class that inherit from ComboBox and override
virtual void ComboBox::showPopup();
On this method I iterate on ComboBox items with
PopupMenu::MenuItemIterator iterator(*getRootMenu(), true); and create a new PopupMenu according to rootMenu and separators. then I show the newly created menu instead of the rootMenu one with PopupMenu::showMenuAsync() like in the ComboBox::showPopup() code.
Hopping all of this can helps
The best.
https://docs.juce.com/master/classComboBox.html#ada8ab191b09811f989a0df42e26dcd8b
PopupMenu* ComboBox::getRootMenu ( )
Returns the PopupMenu object associated with the ComboBox.
Can be useful for adding sub-menus to the ComboBox standard PopupMenu
so wait, I use getRootMenu() to get the Popup menu, then I can add items to it from there?
That’s what the documentation says to do! Good luck!
You can add a sub menu(PopupMenu) to a combobox with getRootMenu()->addSubMenu().