Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make the menuBar and toolBar on one line like VMWare....?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 695 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by
    #1

    0_1538317916676_20180930_222933.png

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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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);
      
      LimerL 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        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);
        
        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        @Chris-Kawa Get it! Thanks a lot.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved