PDA

View Full Version : QT layout issue



meraj ansari
17th May 2010, 16:25
Hi,

Currently I am designing UI of my application. I am using QT creator to design UI. UI contain tabwidget, buttons etc.
My problem is related to layout. If i simply drop widget on form(without applying any layout), resize them according to my choice and run application then everything is ok until I resize my application window. Widget are not resized accordingly. Qt documentation suggested layout to handle resizing issue. So i used layout but after placing widgets on layout they are changing their size (tab widget is becoming small and buttons on horizontal layout stretched) and i am not able to resize them. I tried to play with "Size policy" and used "Fixed" but my widgets are not resized according to my choice.

Will you please suggest a solution, so that i can use proper layouting?

Thanks

MorrisLiang
17th May 2010, 16:33
Ok,keep in mind that you have to call the widget's setLayout() function;

Here's an example:
1.Create a new ui class in QtCreator called MyWidget
2.Open the ui file,drag a layout into MyWidget,name it "myLayout".
3.Add stuffs to myLayout.
4.In the constructor of MyWidget,call setLayout():


MyWidget::MyWidget()
{
ui.setupUi(this);
setLayout(ui.myLayout);
}

meraj ansari
17th May 2010, 17:07
Thanks for quick reply.

I created new "QT designer form" derived from "widget template", placed a vertical box ;layout on form and then placed a button on it. After placing button, button was resized automatically by the effect of vertical box layout and i am not able to resize it. plz check the attached image.

Lykurg
17th May 2010, 17:16
change the vertical size policy.

meraj ansari
17th May 2010, 17:28
Thanks.
Something is working, not completely but let me try.

ChrisW67
18th May 2010, 00:33
Thanks for quick reply.

I created new "QT designer form" derived from "widget template", placed a vertical box ;layout on form and then placed a button on it. After placing button, button was resized automatically by the effect of vertical box layout and i am not able to resize it. plz check the attached image.

You currently have a layout that is not attached to a parent container widget.

Try this:

Create a blank form or widget.
Drop your push button on the form.
Select the form.
On the Designer tool bar select the tool for Layout Vertically. Alternately, use the option in the Form menu.

The form now has the selected layout applied. The layouts you see in the widget palette can be placed on a form, within its existing layout, to contain more complex sub-layouts of widgets.