Wednesday, February 27, 2013

Qt menu and OS X

One strange issue I noticed with crazyflie-pc-client is that it appeared to be missing some menubar items.  Specifically, "Configure Input device", "Exit", "Options", and "Help".  It took some digging but I finally found this:

QMenuBar on Mac OS X

QMenuBar on Mac OS X is a wrapper for using the system-wide menu bar. If you have multiple menu bars in one dialog the outermost menu bar (normally inside a widget with widget flag Qt::Window) will be used for the system-wide menu bar.
Qt for Mac OS X also provides a menu bar merging feature to make QMenuBar conform more closely to accepted Mac OS X menu bar layout. The merging functionality is based on string matching the title of a QMenu entry. These strings are translated (using QObject::tr()) in the "QMenuBar" context. If an entry is moved its slots will still fire as if it was in the original place. The table below outlines the strings looked for and where the entry is placed if matched:
String matchesPlacementNotes
about.*Application Menu | About <application name>The application name is fetched from the Info.plist file (see note below). If this entry is not found no About item will appear in the Application Menu.
config, options, setup, settings or preferencesApplication Menu | PreferencesIf this entry is not found the Settings item will be disabled
quit or exitApplication Menu | Quit <application name>If this entry is not found a default Quit item will be created to call QApplication::quit()
You can override this behavior by using the QAction::menuRole() property.

So, Qt parses the name of the menu bar items, and if they even partially match certain string (e.g., "configure"), it will move the item into what it thinks is a Mac native menu bar!!

Since this is probably not what we want here, adding the following to an action disables this feature:

   <property name="menuRole">

For example:

  <action name="menuItemConfInputDevice">
   <property name="text">
    <string>Configure Input device</string>
   <property name="menuRole">


  1. Just seen your blogs which I will be following as like you I use Mac's and have a Crazyflie on order, though not had the chance to try software yet.
    Keep up the great work!

    1. Cool, thanks - lemme know what you learn as well, seems like there's only a few of us attempting to use Crazyflie + OS X at the moment. I've been pushing my changes upstream as well so you should get them when you sync. Cheers!

  2. Wow thanks! Spent an hour looking for a solution to this.

  3. Thanks a lot! I was looking for this information :)