Menu bar help

Hi, I’m adding a menu bar to my app and have a couple of issues:

image

  1. Everything is greyed out, even if I call setActive( true ) on the ApplicationCommandInfo. Once I click anywhere else in the window or operate another control, the menu works as expected, but if it’s the first thing I click on after the app starts then it doesn’t.
  2. The menu text is twice the size of the menu bar text.

The menus demo works fine even without any calls to setActive().

Any ideas? thx

I believe as the MenuBar created a PopupMenu, the size of the text is determined by LookAndFeel::getPopupMenuFont().

As for the greyed out menu, I’ve found this is normally solved by calling setWantsKeyboardFocus() on one of the child components to grab focus on construction. The ApplicationCommandManager can then find the ApplicationCommandTarget which will be used to handle the command triggered from the menu bar (finding the correct target by calling ApplicationCommandTarget::getNextCommandTarget).

1 Like

thx for the tips.

When you say “one of the child components”, which child components are you actually talking about? thx

I poorly explained. I would set keyboard focus on one of the components which also inherits the ApplicationCommandTarget which can handle the commands that would be invoked by the menubar. If the commands are across multiple components/ classes then ApplicationCommandTarget::getNextCommandTarget() will be used to find the next ApplicationCommandTarget which can handle the command. You can also force the ApplicationCommandManager to a certain ApplicationCommandTarget first using ApplicationCommandManager::setFirstCommandTarget().

1 Like

Thanks, this call worked - thx for the assist!