View Full Version : QToolBar Layout(when part of QMainWindow)

4th August 2009, 21:51
Iam trying to add QAction icon with spaces. I have about 5 icons and I want 2 icons to be aligned to the extreme right and the other three to be aligned to the extreme left.
Iam trying to do the above to the QToolBar which is added to the QMainWindow.

When I look at the source code, it seems QToolBar uses the QToolBarLayout and doesnt seem to be very flexible. I tried adding a spacer to a widget, it doesnt work, I tried all sorts of other things, it just would not align properly.
Suggestions are welcome

5th August 2009, 22:45
Iam going to try to answer this myself, I had to workaround the problem of not being able to set Layouts in a QToolbar added to QMainWindow by not using a QMainWindow.

So when I created a QWidget with QVBoxLayouts, I was able to set layout to the QToolBar and I was able to align QActions.

21st October 2009, 14:10
It's never too late ^^.

I had the same problem you are describing. I needed to put widgets in the bottom of the QToolBar. There is nothing to help us. I finally also used a intermediate QWidget :

QWidget *w = new QWidget(this); // "this" is a pointer to a QToolBar
QVBoxLayout *vbox = new QVBoxLayout(w);


and it worked for me ! Is there a better/"normal" way to achieve that ?

18th April 2013, 14:19
I was also using the same approach, but recently I noticed in Qt5 it creates problems: QToolButton doesn't look like a real button. When you click it the button is not redrawn as pressed, no mouse hover decorations either. Tested on Mac OS X 10.7, 10.8, Qt5.0.1, Qt5.0.2. Any ideas how to fix this?