Important: Please read the Qt Code of Conduct -

Os X native menu bar not populated on first show

  • I'm having an issue with my menubar on a QMainWindow, on Os X.

    After my window is shown the global menu bar is not correctly populated. There is the main application with About/Preferences/Quit present (all of which work) but I'm not seeing any of my other menus. (File, Edit, View etc...)

    Switching focus to another window and back again repopulates the global menu correctly. (Switching to another app, opening the preferences dialog and closing it again...)

    If I turn native menus off then they appear just fine along the top of the window, but this is not really optimal.

    I've tried various bits of trial and error including turning native menus off until showEvent, and then turning back on... Calling setMenuBar in showEvent to reset the menu, trying to activateWindow in showEvent... I'm not really sure what I'm doing though and this is mostly guesswork.

    Has anyone seen this before? If so, how did you fix it? Google suggests it's not a very common problem.

  • Lifetime Qt Champion

    HI and welcome to devnet,

    You should also share which edition of OS X you are using as well as Qt version.

    Also, you should post the code where you setup your menu

  • It's Qt 5.4 on 10.10...

    The menu is created as part of the mainwindow .ui file. There's nothing special to initialise it after that apart from connecting slots to actions.

    Obviously this usually works, but something must be getting in the way. It's an oss project I'm trying to get working on osx so I'm not familiar with the fine details of it. There's a big class that does a bunch of stuff here: -- but there's a lot of code so you'd be forgiven for not looking at it. :-)

    What I'm really wondering is whether anyone has seen this before, or knows enough about the menubar internals to explain how I can force the global menu bar to refresh itself from the one that's there? -- It obviously works when the window is refocused, but I'd like to "simulate" this at the point where it's gone wrong.

  • Lifetime Qt Champion

    From a quick overlook of the files and the menu related code, nothings stands out that could trigger that. Can you check if you still have this with Qt 5.5 ?

  • @SGaist I've just tried it with 5.5 instead of 5.4, but it didn't make a difference unfortunately. :/

  • For anyone landing here from google, I worked around this by saying emit qGuiApp->onFocusWindowChanged(windowHandle()); in my main window's show event.

    The method to update the native window is hooked up to this event.

  • Lifetime Qt Champion

    Thanks for the workaround but it's fishy at best. There might be some bug lurking around

Log in to reply