QMenuBar in QWidget windows
-
wrote on 1 Oct 2021, 14:12 last edited by
Good afternoon.
Quick question: is it possible to have QMenuBar on something else than QMainWindow?
I tried to get the result but failed.
I created the QWidget base empty window and added to the constructor:ui->setupUi(this); QMenuBar *menuBar = new QMenuBar(this); QMenu *browser = new QMenu(menuBar); QAction *closeAction = new QAction("Close",browser); browser->addAction(closeAction); menuBar->insertMenu(nullptr,browser);
When I do show() and raise() this widget window it does get shown but without the menu bar... I am working on Qt 5.15.2.
-
Good afternoon.
Quick question: is it possible to have QMenuBar on something else than QMainWindow?
I tried to get the result but failed.
I created the QWidget base empty window and added to the constructor:ui->setupUi(this); QMenuBar *menuBar = new QMenuBar(this); QMenu *browser = new QMenu(menuBar); QAction *closeAction = new QAction("Close",browser); browser->addAction(closeAction); menuBar->insertMenu(nullptr,browser);
When I do show() and raise() this widget window it does get shown but without the menu bar... I am working on Qt 5.15.2.
wrote on 1 Oct 2021, 14:57 last edited by@artwaw
I believe so. Googling suggests you should be following this: http://redino.net/blog/2014/05/qt-qwidget-add-menu-bar/ -
@artwaw
I believe so. Googling suggests you should be following this: http://redino.net/blog/2014/05/qt-qwidget-add-menu-bar/wrote on 1 Oct 2021, 15:22 last edited by@JonB I don't know how this didn't pop up in my google search before I asked. It works, of course.
The funny thing is that I considered using the layout (since I am prototyping now and finding out which solutions might be usable) - layouts would be used at the end anyway of course - but dropped the idea thinking "why bother for the prototype".
Thank you!
-
@JonB I don't know how this didn't pop up in my google search before I asked. It works, of course.
The funny thing is that I considered using the layout (since I am prototyping now and finding out which solutions might be usable) - layouts would be used at the end anyway of course - but dropped the idea thinking "why bother for the prototype".
Thank you!
-
@artwaw keep a test case with ui file generated from designer. In this case, add menubar to mainwindow in designer. Then build your test case and check ui_*** file. You will be able to know how it is added.
1/5