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. QToolBar widgets spacing
Forum Updated to NodeBB v4.3 + New Features

QToolBar widgets spacing

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtoolbarcontent margins
2 Posts 2 Posters 5.0k Views
  • 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.
  • J Offline
    J Offline
    Joel Bodenmann
    wrote on 30 Mar 2016, 10:55 last edited by
    #1

    I am adding a QSpinBox and a QComboBox to a QToolBar using QToolBar::addWidget(). It actually does what it is supposed to and I can successfully use the widgets. However, I am not happy with the spacing of the widgets. The two widgets are glued together one next to each other, there's not a single pixel of space in between them:

    Issue

    How can I change this? I tried to play around with QToolBar::setContentMargins(10, 10, 10, 10) but that only added padding to the bottom of the widgets.
    Basically I would like them to be spaced apart like when I add a separator between them using QToolBar::addSeparator():

    Expected result

    My code looks like this:

    QToolBar* toolbarDocument = new QToolBar;
    toolbarDocument->addWidget(new QSpinBox);
    toolbarDocument->addWidget(new QComboBox);
    addToolBar(toolbarDocument);
    

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 30 Mar 2016, 16:28 last edited by
      #2

      Did you try doing it outside of the QToolBar?

      QWidget* spinWidget = new QWidget;
      QHBoxLayout* spinLay = new QHBoxLayout(spinWidget);
      spinLay.addWidget(new QSpinBox(spinWidget));
      spinLay.setContentsMargins(0,0,10,0); // Here you set the spacing
      QToolBar* toolbarDocument = new QToolBar;
      toolbarDocument->addWidget(spinWidget );
      toolbarDocument->addWidget(new QComboBox);
      addToolBar(toolbarDocument);
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0

      1/2

      30 Mar 2016, 10:55

      • Login

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