PDA

View Full Version : Layout in Qt Designer



eiswand
5th December 2010, 11:10
Hello guys!

I am a total Qt beginner and I am still struggling a little bit with layouts. My 2 questions:

1) When I create a layout per code I make it like this:

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
I explicitly set the layout of this widget by calling setLayout(). But when I create my Window in the Qt Designer, there isn't a call to setLayout() at all! The only thing I noticed was this:

verticalLayout = new QVBoxLayout(centralwidget);
verticalLayout = new QVBoxLayout(centralwidget);
Does this line mean the centralwidget now has a vertical layout? Or is this just used for resource management (so that the layout is deleted when the centralwidget is deleted)?

2) Lets take the example from question 1: 3 buttons in a horizontal layout. I don't understand why each button has a Horizontal and Vertical Stretch AND the layout itself also has a layoutStretch (0,0,0). How are they related? Does the layoutStretch values of the QHBoxLayout override the horizontal strech values of the contained widgets?

Thanks!

franz
5th December 2010, 19:44
Does this line mean the centralwidget now has a vertical layout? Or is this just used for resource management (so that the layout is deleted when the centralwidget is deleted)?Both. If I remember correctly the setLayout() way of doing things ensures the layout is resized with the widget. The other doesn't or didn't. I always use the setLayout method as well.


) Lets take the example from question 1: 3 buttons in a horizontal layout. I don't understand why each button has a Horizontal and Vertical Stretch AND the layout itself also has a layoutStretch (0,0,0). How are they related? Does the layoutStretch values of the QHBoxLayout override the horizontal strech values of the contained widgets?The stretch factors on widgets tell the containing layout how to handle the resizing. You can also tell the layout to set a certain stretch factor on a widget. However, I think that the layoutStretch (which I cannot find by that name in the documentation) would be the stretch factor of the layout itself. That would make sense to me since the layouts can be embedded in other layouts.

wysota
5th December 2010, 22:24
I never use setLayout() and my layouts and widget sizes are always fine.