PDA

View Full Version : Position of qActions inside a QToolBar



jano_alex_es
4th June 2009, 08:49
Hi,

I have a QToolBar with seven "buttons" on it, I didn't want to have a normal menu (File, Edit, Tools...) as I just needed few buttons, I created seven QActions inside, working as buttons.

I would like to ask if I could move them, for instance, the first five in the left side of the screen and the last two in the right side.

I'd prefer to keep this structure because QToolBar is movable, it floats... really confortable for the user of the application.

Thanks!

wysota
4th June 2009, 09:10
Create two toolbars - one with the first five actions and the other one with the remaining two. Then you can move them around freely.

jano_alex_es
4th June 2009, 10:01
yep, that was something I was trying as well... but changing the X coordenade of "Geometry" didn't affect its position at all.

In the end, I just needed to set LyoutDirection(Right to Left) in the right one.

jano_alex_es
4th June 2009, 11:48
It works fine when the toolbar is settled horizontaly... but if you move both toolbar vertically the second one shows always its actions in its upper part... but I'd like to have them in the lower part...


http://i41.tinypic.com/jg5htf.jpg

http://www.freeimagehosting.net/uploads/8e588e2333.jpg

Lykurg
4th June 2009, 12:51
Without any testing and promise that it could work:

Use a third bar where you set a expanding spacer via QToolBar::addWidget(). Then use the signal which informs you if tool bars have changed and make sure that that spacer tool bar is always between the two others.


AGAIN: I don't have a clue if that is working, came just in my mind. Could work...

wysota
4th June 2009, 12:54
It's probably better to have one bar with an extra widget using heightForWidth. Provided it would work at all :)

Lykurg
4th June 2009, 13:21
It's probably better to have one bar with an extra widget using heightForWidth. Provided it would work at all :)

And again I am feeling ashamed because I have only read "Adds the given widget to the toolbar as the toolbar's last item." and was only thinking that with the second toolbar alone it won't work, ignoring one could also use the first one...:o

So jano_alex_es it's up to you to try if this works and please notice us.

pedromorgan
5th June 2009, 03:23
To align to the right I used this as a widget/spacer.
This QToolbar shuld have an addSpacer() or similar

## Spacer widget
w = QtGui.QWidget()
sp = QtGui.QSizePolicy()
sp.setHorizontalPolicy( QtGui.QSizePolicy.Expanding )
w.setSizePolicy( sp )
toolbar.addWidget( w )

jano_alex_es
5th June 2009, 09:23
Seems like it's not working either



QWidget w;

//first try
//w.setMinimumWidth(100);

//second try, with all the different flag possibilities
/*QSizePolicy sp;
sp.setHorizontalPolicy( QSizePolicy::Expanding);
sp.setVerticalPolicy( QSizePolicy::Expanding);

w.setSizePolicy( sp );*/

ui.toolBar2->insertWidget(ui.firstQActionInTheSecondToolbar, &w);


I'll try the third toolbar with a widget expanding which will be always before the second toolbar.

zaphod.b
23rd April 2010, 10:29
Sorry for digging out this ancient threat, but I have the exact same problem. Any solution by now?

I can prevent expansion of the second toolbar by calling

secondToolbar->layout()->setSizeConstraint(QLayout::SetFixedSize);
but the same approach won't help expand the first toolbar with either constraint. Plus, this will fix both width and height, which is not really what you want.

Thanks for your consideration.