PDA

View Full Version : Two widgets in a QLayout



zack
15th June 2009, 12:53
Hello,

I have two widgets, which I want to insert in a QVBoxLayout.
The first widget is much smaller, then the second one.
But unfortunately, the two widgets using exact the same size, it's the perfect half size of the Layout.

How can I change this behaviour?

Lykurg
15th June 2009, 13:00
QBoxLayout::addWidget ( QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0 )

Use the second parameter or alter the QSizePolicy of the widgets.

zack
15th June 2009, 13:18
I thought about changing the sizepolicy in the smaller widget, but I got strange results.

e.g.

this->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixe d);

Lykurg
15th June 2009, 13:27
In your case it should be the best using the stretch parameter. Have you tried that?

zack
15th June 2009, 13:33
yes, this works, but I find this is some kind of manually. I would find it better if the layout is automatically resized to the size of the smaller widget.

e.g. when I inser directly a QComboBox, then the layout for the box is only as big as the box.

wysota
16th June 2009, 09:18
What is the size policy of the bigger widget? If you set it to preferred/preferred or maximum/maximum and the smaller widget to minimum or fixed then the layout should adjust. Note it will not work if the parent of the two widgets is a top-level window. Then you'll need to set a constraint on the window's layout.

shivendra46d
26th December 2012, 07:40
hii everyone i am new to Qt and want to implment Analog and digital clock in same ui can any one tell me how to do this ??