Native Menu bar on macOS
-
wrote on 13 Oct 2016, 05:32 last edited by sandy.martel23
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.
-
wrote on 13 Oct 2016, 06:58 last edited by
Hi,
you can try it this way:QMenuBar *m = new QMenuBar(0); QMenu *menu = m->addMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" );
-Michael.
-
Hi,
you can try it this way:QMenuBar *m = new QMenuBar(0); QMenu *menu = m->addMenu( "menu 1" ); menu->addAction( "action 1" ); menu->addAction( "action 2" );
-Michael.
wrote on 13 Oct 2016, 20:55 last edited by@m.sue
Explicitly specifying what is the default parent (0) ?
Nah, I tried, even if I couldn't see how that would help. -
Hi,
Which version of macOS are you running on ?
-
wrote on 14 Oct 2016, 00:58 last edited by
@SGaist
I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem. -
@SGaist
I tried 10.9, 10.11 and 10.12. This seems irrelevant to the problem.wrote on 14 Oct 2016, 01:07 last edited byworkaround:
#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(); }
-
@m.sue
Explicitly specifying what is the default parent (0) ?
Nah, I tried, even if I couldn't see how that would help.wrote on 14 Oct 2016, 09:49 last edited by@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. -
@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.wrote on 16 Oct 2016, 22:32 last edited by@m.sue
Yes Qt5 seems to require a window to show up as the application starts. Anyway, my workaround works. -
wrote on 10 Nov 2016, 23:10 last edited by