[solved]How to center toolbuttons in horizontal toolbar?
-
[quote author="SGaist" date="1400537649"]IIRC there's no such thing out of the box. However you can set two "spacer" QWidgets, one on the left and one on the right side of your actions.[/quote]
I tried that and set them to maximize, but somehow the one on the left maxed and pushed everything to the right. And the right one did nothing?
I am sorry for asking such noob questions. -
i used
@ QWidget *spacerWidget = new QWidget(this);
toolbar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
spacerWidget->setVisible(true);@and before and after the actions:
@toolbar->addWidget(spacerWidget);@ -
You should set the policy on the widgets, not the toolbar
-
oh wow, so i just change it into spacerWidget->SetSizePolicy ?
Im gonna try this right away. -
[quote author="SGaist" date="1400570992"]You should set the policy on the widgets, not the toolbar[/quote]
i tried this but it didnt work..am i still doing something wrong?@void BitcoinGUI::createToolBars()
{
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));
QWidget *spacerWidget = new QWidget(this);
spacerWidget>setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
spacerWidget->setVisible(true);
toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
toolbar->addWidget(spacerWidget);
toolbar->addAction(overviewAction);
toolbar->addAction(sendCoinsAction);
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
toolbar->addAction(addressBookAction);
toolbar->addWidget(spacerWidget);
@ -
You need two spacer widgets, otherwise you are just moving it from left to right
-
[quote author="SGaist" date="1400707308"]You need two spacer widgets, otherwise you are just moving it from left to right[/quote]
So i cannot use toolbar->addWidget(spacerWidget);
twice?
I have to make like a spacerwidget2? -
No you can't, addWidget doesn't mean "copy that widget in the toolbar" (you can't copy widgets by the way nor any QObject derived class)
So yes you have to create another spacer widget
-
Thank you so much for all of your time and help! I really appreciate it.
-
You're welcome !
Did you got it working ?
-
[quote author="SGaist" date="1400775959"]You're welcome !
Did you got it working ?[/quote]
Yes it works perfectly -
Nice ! Then please update the thread title prepending [solved] so other forum users may know a solution has been found :)