PDA

View Full Version : How do I add a QSpacerItem to a toolbar?



di_zou
9th February 2010, 21:13
Since a QSpacerItem does not inherit QWidget, I can't use addWidget(). So how do I add a spacer to a toolbar?

kichi
9th February 2010, 21:41
Since a QSpacerItem does not inherit QWidget, I can't use addWidget(). So how do I add a spacer to a toolbar?

You can use QToolBar's addSeparator() or insertSeparator().

di_zou
10th February 2010, 17:08
All addSeperator() did was add this little vertical line. I was hoping to add more space and have the ability to customize the scaling and such.

phillip_Qt
11th February 2010, 03:12
All addSeperator() did was add this little vertical line. I was hoping to add more space and have the ability to customize the scaling and such.

Hi Di_Zou,
even i'm also trying same thing, to add spaceritem in toolbar. If u've done this, plz tell me how to do.
Thank u.

axeljaeger
12th February 2010, 09:55
Add an empty QLabel. The only downside of this I found so far is that you wont be able to move the window around on macos when clicking on that empty space made by the label.

msappy00
23rd June 2021, 02:12
Add a QWidget instead of a QSpacerItem, set the size policy on the spacer and add the widget to the toolbar.


QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
toolBar->addWidget(spacer);