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 center a QToolBar at QMainWindow?
Forum Updated to NodeBB v4.3 + New Features

How to center a QToolBar at QMainWindow?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 3.0k 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.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    Hi,
    I have been looking for a solution for this question in several forums and I have found several approaches but I didn't like any of them.
    Using this line I can set my toolbar in the bottom of my app:

    addToolBar(Qt::BottomToolBarArea, myToolbar); 
    

    But it is always left-aligned, is there a way to set it in the middle of that bottom panel? Also, Is there a way to make it look similar to the dock of the OSX desktop?

    Thanks!


    Qt Developer

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

      To keep it simple you can insert two expanding dummies at the start and end of the toolbar:

      auto dummy1 = new QWidget(this);
      dummy1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
      auto dummy2 = new QWidget(this);
      dummy2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
      
      auto tb = new QToolBar();
      tb->addWidget(dummy1);
      tb->addAction("foo");
      tb->addAction("bar");
      tb->addAction("bazz");
      tb->addWidget(dummy2);
      
      addToolBar(Qt::BottomToolBarArea, tb);
      
      1 Reply Last reply
      2
      • X Offline
        X Offline
        xtingray
        wrote on last edited by
        #3

        Thanks! It worked perfect for me :)

        PS: I still miss the day you could do something like:

        addToolBar(Qt::BottomToolBarArea|Qt::CenterToolBarArea , myToolbar); 
        

        Qt Developer

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

          Toolbar area in main window and buttons alignment within a toolbar are two entirely separate concepts so it wouldn't make sense to put these two options together.
          Would be nice however if there was something like QToolBar::setAlignment(Qt::Alignment), although toolbars can be placed on the sides too, so directions become a little fuzzy.

          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