Friday, July 4th 2008, 9:42pm UTC+1

You are not logged in.

  • Login
  • Register

matic

Beginner

Posts: 12

Location: italy

1

Friday, September 7th 2007, 11:58pm

Understanding the resize and the auto expand behavior

This is probably a newbie question, but i didn't understard how the resizing works under qt (4.3.1).
I'm using the designer to make a simple dialog; there is just a GroupBox inside it, and a TextEdit inside the box. I just want that, whenever the user resize the form, the GroupBox size, and then the TextEdit size have to become as large as the parent form.
I tried almost any combination of sizePolicy but with no success, even if the policy "Expanding" sounded me very friendly.
What options I have to set ?

Thank you
Mtc
  • Go to the top of the page

2

Wednesday, October 24th 2007, 12:45pm

i have a solution

i was also facing the same problem and i have solved by coding.
first put all the widgets in to a layout and in the ui_designerfilename.h file you will find a name for the layout widget layoutWidget now use the resize event function of designer form by subclassing designer form and inside the resize event ,resize the layoutWidgetto the size of central widget of ui_designerfile


never worry if u dont understand send me the source code i will help u .


bye

This post has been edited 2 times, last edit by "babu198649" (Oct 24th 2007, 12:47pm)

  • Go to the top of the page

lifthrasir

Trainee

Posts: 159

Location: France

Occupation: Student

3

Wednesday, October 24th 2007, 1:44pm

RE: i have a solution

The property sizePolicy is a layout behavior, so you need to layout your widgets.

Quoted

From Qt doc

sizePolicy : QSizePolicy

This property holds the default layout behavior of the widget.


Quoted

Originally posted by babu198649
i was also facing the same problem and i have solved by coding.

You can apply layout directly from the designer there is no need to hand coded this behavior.

Quoted

Originally posted by babu198649

now use the resize event function of designer form by subclassing designer form and inside the resize event ,resize the layoutWidgetto the size of central widget of ui_designerfile

The aim of layout is to don't have to worry about resizing. It is a bad way to reimplement resizeEvent and make manual resizing, it's the purpose of layout!
  • Go to the top of the page

4

Thursday, October 25th 2007, 10:47am

it sounds right but has not worked

i have tried this
QSizePolicy sizePol(QSizePolicy::Expanding,QSizePolicy::Expanding);
ui.layoutWidget->setSizePolicy(sizePol);


even then, the resizing of widgets does not happen when the main window is maximized ,hence i have no way other than resize event(as far as i have known).

This post has been edited 1 times, last edit by "babu198649" (Oct 25th 2007, 10:48am)

  • Go to the top of the page

lifthrasir

Trainee

Posts: 159

Location: France

Occupation: Student

5

Thursday, October 25th 2007, 11:10am

Look at the ui files I have attached.
In untitled_1.ui I put a widget with a vertical layout into the main container (I think it's what you do).
In untitled_2.ui I apply a vertical layout to the main container.
lifthrasir has attached the following files:
  • untitled_1.ui (1.32 kB - 145 times downloaded - Last download: Today, 10:37am)
  • untitled_2.ui (1.08 kB - 137 times downloaded - Last download: Today, 10:37am)
  • Go to the top of the page

6

Thursday, October 25th 2007, 3:38pm

u r form works(untitled_2) ,this is because it doesnot have any layout .
but the actual problem is resizing the layout in designer.
  • Go to the top of the page

lifthrasir

Trainee

Posts: 159

Location: France

Occupation: Student

7

Thursday, October 25th 2007, 5:59pm

Quoted

Originally posted by babu198649

u r form works(untitled_2) ,this is because it doesnot have any layout .

Of course not, I have set a vertical layout to the form. If not when you resize the form, the push buttons will not be resized as it is. To ensure you that i have set a layout, edit the file untitled_2.ui into a text editor and look at the line 15, you will see:

Source code

1
<layout class="QVBoxLayout" >


I think you missunderstand what is a layout. A layout is not a widget, it doesn't inherit QWidget. It's geometry manager. And you can set a geometry manager to a widget with the method QWidget::setLayout(). But a layout is not a widget in its own.

When you say:

Quoted

Originally posted by babu198649

but the actual problem is resizing the layout in designer.

you make mistake, a layout cannot be resized they haven't any method like resize() or setGeometry().

When you edit the file untitled_1.ui with Qt designer, you must see in the object inspector:

Source code

1
2
3
4
Form                    QWidget
+-- verticalLayout      QVBoxLayout
    +-- pushButton      QPushButton
    +-- pushButton_2    QPushButton

but, in reality, it's not exactly that. Actually, verticalLayout is not an instance of QVBoxLayout but an instance of QWidget on which a QVBoxLayout has been set.
  • Go to the top of the page

8

Friday, October 26th 2007, 7:12am

Quoted

Of course not, I have set a vertical layout to the form. If not when you resize the form, the push buttons will not be resized as it is. To ensure you that i have set a layout, edit the file untitled_2.ui into a text editor and look at the line 15, you will see:



right

but i have used the object explorer and i have not found any vertical layout in untitled_2.ui.
when i viewed the ui_untitled_2.h file generated by qmake i found that the parent of the form is
vertical layout. that is what i wanted ,but how did u did it in designer please explain.

Quoted

a layout cannot be resized they haven't any method like resize() or setGeometry().


if a layout cannot be resized then how does it expands(verticallayout) when the form is maximized(since, parent of form is vertical layout)


Source code

1
2
3
4
Form                    QWidget
+-- verticalLayout      QVBoxLayout
    +-- pushButton      QPushButton
    +-- pushButton_2    QPushButton


Quoted

Actually, verticalLayout is not an instance of QVBoxLayout


ok

Quoted

but an instance of QWidget on which a QVBoxLayout has been set.


this i did not understood please explain a bit more


many thanks for u r reply
  • Go to the top of the page

lifthrasir

Trainee

Posts: 159

Location: France

Occupation: Student

9

Friday, October 26th 2007, 9:37am

Quoted

Originally posted by babu198649

when i viewed the ui_untitled_2.h file generated by qmake i found that the parent of the form is vertical layout. that is what i wanted ,but how did u did it in designer please explain.

Right click on the form > Lay out > Lay out horizontaly/verticaly/in a grid (they are corresponding button in the toolbar).

Quoted

Originally posted by babu198649

if a layout cannot be resized then how does it expands(verticallayout) when the form is maximized(since, parent of form is vertical layout)

When you resize a widget, the geometry of their child widgets are updated accordingly to the geometry manager (the layout), if there is one, of the parent widget.
  • Go to the top of the page

10

Friday, October 26th 2007, 10:55am

ya u r right
but it is no where it is documented .

one more question
i want a thumbnail directory view.ie.all the file structure is displayed as a thumbnail view.when the directory(thumbnail) is clicked its contents should again be displayed as thumbnails and if any pictures it should be displayed as picure thumbnail.

the problem is choosing the correct classes due to large options (QListView,QListWidget,QAbstractItemView,e.t.c)

could please suggest the right classes to be used.

This post has been edited 1 times, last edit by "babu198649" (Oct 26th 2007, 11:14am)

  • Go to the top of the page

Rate this thread