Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Spacing and alignment of buttons in a QToolbar
Qt 6.12 LTS is out! See what's new in the release blog

Spacing and alignment of buttons in a QToolbar

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 7.0k Views 2 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    I have added a buddy label and a QSpinBox to the toolbar of my main window which will zoom the contents of a QTextBrowser. This works OK.

    But by default, the toolbar has them all pushed over to the left. I would like to have some buttons on the left side of the toolbar and the zoom spin box over on the right.

    Is there any way to do this without having to call setGeometry() etc. myself on the controls? I believe there is an easy option to do this with a status bar, but not sure about how to do it with a toolbar. Or can I put them in a layout and add that to the toolbar? It's too bad that Qt Designer doesn't seem to allow doing it graphically.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You cant do it Designer however, from code you can do
      the following

        // add left Actions
          QAction *action1 = ui->toolBar->addAction("A1");
      
          // Spacer
          QWidget *spacer = new QWidget();
          spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
          ui->toolBar->addWidget(spacer);
      
          // add right Actions
          QAction *action2 = ui->toolBar->addAction("A2");
      
      

      alt text

      R 1 Reply Last reply
      6
      • mrjjM mrjj

        Hi
        You cant do it Designer however, from code you can do
        the following

          // add left Actions
            QAction *action1 = ui->toolBar->addAction("A1");
        
            // Spacer
            QWidget *spacer = new QWidget();
            spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
            ui->toolBar->addWidget(spacer);
        
            // add right Actions
            QAction *action2 = ui->toolBar->addAction("A2");
        
        

        alt text

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @mrjj Fantastic! You have saved me so much time ... thank you very much!

        1 Reply Last reply
        2

        • Login

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