Native Menu bar on macOS
Unsolved
General and Desktop
-
How do I create an application that start with just a filled menu bar on macOS?
The following code works with Qt 4.8.7, 5.3.2 and 5.5.1 but does not with 5.6.1, 5.6.2 and 5.7.
#include <QApplication> #include <QMenuBar> #include <QMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMenuBar *m = new QMenuBar; QMenu *menu = new QMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" ); m->addMenu( menu ); return a.exec(); }
No menu is shown with Qt 5.6.1 and 5.6.2.
-
Hi,
Which version of macOS are you running on ?
-
workaround:
#include <QApplication> #include <QMenuBar> #include <QMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMenuBar *m = new QMenuBar; QMenu *menu = new QMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" ); m->addMenu( menu ); m = new QMenuBar; // <-- Qt5.6, this seems to force the previous menu to show up m->deleteLater(); return a.exec(); }
-
@sandy.martel23 said in Native Menu bar on macOS:
even if I couldn't see how that would help
I did just copy what works here.
Maybe the Application needs to have a QMainWindow. At least, we call the code inside a QMainWindow derived class.
-Michael. -