Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to make the menuBar and toolBar on one line like VMWare....?



  • 0_1538317916676_20180930_222933.png

    Just like the above pic, how I can make the same result in Qt?


  • Moderators

    Menu bar is a widget like any other so you can just add it to the toolbar:

    QMenuBar* menuBar = new QMenuBar();
    QToolBar* toolBar = new QToolBar();
    
    toolBar->addWidget(menuBar);
    

    Another way is to put them together in a horizontal layout:

    QWidget* wrapper = new QWidget();
    wrapper->setLayout(new QHBoxLayout());
    wrapper->layout()->setContentsMargins(0,0,0,0);
    wrapper->layout()->addWidget(menubar);
    wrapper->layout()->addWidget(toolbar);
    
    yourMainWidget->layout()->setMenuBar(wrapper);
    


  • @Chris-Kawa Get it! Thanks a lot.


Log in to reply