PDA

View Full Version : Widget Resize



manojmka
19th May 2010, 10:59
I have a widget with lot of widgets placed on it and arranged in a layout. I want to show this widget on a specific area of screen, say centre. Henceforth, I calculate x,y,width and height for this and call widget->setGeometry(x,y,width,height) before calling widget->show(). It sets x and y position correctly but always stretches it's width and height to full available screen size. It seems lot of widgets on main widget makes it doing it so. Is there no way, I can force it to show with specific width and height?

high_flyer
20th May 2010, 10:32
you could use setMaximumWidth() and setMaximumHeight().

manojmka
20th May 2010, 11:57
I tried all of those functions e.g. setMaximumWidth(), setMaximumHeight(), sizePolicy, setGeometry(), resize() but it is always bigger than my description of size. My screen resolution is 720x480 and I want to show this widget in centre of screen with size 300x200 for example.

aamer4yu
20th May 2010, 12:29
What about using QWidget::setFixedSize :rolleyes:

high_flyer
20th May 2010, 12:47
it could be that you are updating the geometry (maybe even without knowing it) somewhere else.

manojmka
21st May 2010, 08:08
Thanks aamer4yu. SetFixedSize() works :)
The only problem is, it does not resize children widgets in similar fashion. some children widgets are visible in full size and some of them are crushed!

high_flyer
21st May 2010, 09:13
The only problem is, it does not resize children widgets in similar fashion. some children widgets are visible in full size and some of them are crushed!
setFixedSize() only fixes the size of the widget you called it on, so no wonder the children are not fixed.
You have to manage the layout in which the children live to get the size you want for the children.

manojmka
21st May 2010, 09:52
I did not get you. Do you mean I have to resize the layout manually?

high_flyer
21st May 2010, 10:08
No.
Have a look at the QLayout and its derivatives documentation and read about stretch factors, and other parameters you can set to make your Layout respond correctly to your needs.
In addition you have to choose the layout that best suits the situation you have, and possibly, you have to set min/max sizes for the children widgets, so that they stay in size range.
Spacers might also be needed.

I usually test my layouts in Designer, since its a fast way to see imminently what it looks like and how it behaves.

manojmka
21st May 2010, 12:32
Thanks. I have all layouts nicely placed on this widget, but I will look more deeper into this.