PDA

View Full Version : Widget does not resize correctly



Demandred
15th April 2010, 09:02
Hello everybody.

I have the following layout in my Widgets:

Widget 1:
A QWidget (named extWidget) and a Groupbox containing pushbuttons in a vertical layout. Groupbox has max height. QWidget fills the rest of the screen: sizePolicy(expanding,expanding).

Widget 2:
9 pushbuttons in a GridLayout.

Now when the first Widget is created. I create the 2nd Widget with the extWidget as parent.

Now when I run my code the 2nd widget gets displayed in the extWidget area of the 1st. So far so good.
But the 2nd widget is displayed with its size as set at design time and when I resize the 1st widget, the 2nd does not change.

How can I get my 2nd widget to alter its size to the available space of the extWidget area of the 1st?



// Code from the constructor of the 1st widget
m_ui->setupUi(this);
// Create the 2nd Widget
StdConfig = new unitconfigStd(m_ui->extWidget);
StdConfig.show();



Thank you for your time,
D

zgulser
15th April 2010, 12:19
look at size policy property of widgets

Demandred
16th April 2010, 08:21
Hi zgulser
Thank you for your reply.

In my opinion I tried all different settings, but the result remains the same. The widget does not resize at all.
I will try to add my sources as a zip-file to this thread. Maybe somebody can take a look at what I'm doing and point me in the right direction.

ChrisW67
16th April 2010, 09:23
What layout have you set on extWidget? Sounds like it is missing.

Demandred
16th April 2010, 12:06
hmz. that could be the case. I cannot set the layout @ designtime (in Creator).
So I guess I will have to do that @runtime after I added the child widget to extWidget?
I'll try to figure this out... If I cannot get it to work I'll return to the forum again :D


After some fumbling around with the layout(s) I got it to work.
Thanks everybody for the input!

Solution:
I created the Config screen at runtime (extWidget as parent).
After that I set the SizePolicy of the Config screen to [Expanding,Expanding] in code.
(Don't know why I had to, but it is somehow required for the desired result.)
Then I created a QVBoxLayout which has the extWidget as parent.
I added the Config widget to the layout,
and set the new created layout to the extWidget.