Qt-interest Archive, October 2007
Enlarge Widget when Window enlarges
Message 1 in thread
Hi,
I have a dialog window with a
- QGraphicsView item as "central" widget
- OK and cancel button in the lower right corner
It is created using Qt Designer.
When I enlarge the window I want that the QGraphicsView enlarges as well,
but the two buttons stay at the same size in the lower right corner.
The sizePolicy of QGraphicsView is set to expanding. As far as I understood
the documentation that should be correct. What I completely didn't
understand is the stretch. What does that do? Regardless if set to 0 or to
2 (in case it is some factor the widget size gets multiplied, so I have
chosen some positive value), it doesn't help.
What do I have to do?
Thanks!
--
[ signature omitted ]
Message 2 in thread
On 13.10.07 20:01:33, KH wrote:
> Hi,
>
> I have a dialog window with a
>
> - QGraphicsView item as "central" widget
> - OK and cancel button in the lower right corner
>
> It is created using Qt Designer.
>
> When I enlarge the window I want that the QGraphicsView enlarges as well,
> but the two buttons stay at the same size in the lower right corner.
For that to happen all you need is put a layout around the graphicsview,
just click on an "empty" area and then select a layout from the toolbar.
> The sizePolicy of QGraphicsView is set to expanding. As far as I understood
> the documentation that should be correct. What I completely didn't
> understand is the stretch. What does that do? Regardless if set to 0 or to
> 2 (in case it is some factor the widget size gets multiplied, so I have
> chosen some positive value), it doesn't help.
stretch only makes sense when used on multiple widgets, it tells the
layout how much to enlarge each of the widgets when the window is
enlarged. The numbers you set are relative to each other, i.e. if
widget w1 has a stretch of 3 and w2 a stretch of 6 then w2 will always
get double as much extra space as w1.
Andreas
--
[ signature omitted ]
Message 3 in thread
> For that to happen all you need is put a layout around the graphicsview,
> just click on an "empty" area and then select a layout from the toolbar.
I have a horizontal layout for "spacer, OK Button, Cancel Button" and a
vertical layout for "QGraphicsView, the horizontal layout from above". With
click an empty area you mean mark the objects which should belong to the
layout, do you? That's at least what I did.
> stretch only makes sense when used on multiple widgets, it tells the
> layout how much to enlarge each of the widgets when the window is
> enlarged. The numbers you set are relative to each other, i.e. if
> widget w1 has a stretch of 3 and w2 a stretch of 6 then w2 will always
> get double as much extra space as w1.
Okay, just to be on the save side I've set the stretch factor for the
QGraphicsWidget to 1.
It still doesn't work.
One additional question, should I see that resize behaviour already in the
preview mode of Qt designer?
I've attached my UI file.
Thanks!
<ui version="4.0" >
<ui version="4.0" >
<class>TestApp</class>
<widget class="QDialog" name="TestApp" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>353</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<widget class="QWidget" name="" >
<property name="geometry" >
<rect>
<x>20</x>
<y>21</y>
<width>421</width>
<height>311</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QGraphicsView" name="graphicsView" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>231</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton" >
<property name="text" >
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>TestApp</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>369</x>
<y>253</y>
</hint>
<hint type="destinationlabel" >
<x>179</x>
<y>282</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Message 4 in thread
On 14.10.07 07:47:23, KH wrote:
>
> > For that to happen all you need is put a layout around the graphicsview,
> > just click on an "empty" area and then select a layout from the toolbar.
>
> I have a horizontal layout for "spacer, OK Button, Cancel Button" and a
> vertical layout for "QGraphicsView, the horizontal layout from above". With
> click an empty area you mean mark the objects which should belong to the
> layout, do you? That's at least what I did.
No, I mean find a place on your form thats not occupied by any widget
(that should select the form, visible in the object browser) and apply a
layout to it. All you've done is creating a vertical layout that you can
now move around on your dialog, unless its the dialogs layout it won't
get resized with the dialog. So remove it and re-create it as I said
above.
> > stretch only makes sense when used on multiple widgets, it tells the
> > layout how much to enlarge each of the widgets when the window is
> > enlarged. The numbers you set are relative to each other, i.e. if
> > widget w1 has a stretch of 3 and w2 a stretch of 6 then w2 will always
> > get double as much extra space as w1.
>
> Okay, just to be on the save side I've set the stretch factor for the
> QGraphicsWidget to 1.
>
> It still doesn't work.
2 thins: a) see above, you need your widgets in a layout applied to the
dialog
b) unless there's another widget with a stretch-factor != 0 (in the same
direction, i.e. vertical or horizontal) you won't see anything anyway.
> One additional question, should I see that resize behaviour already in the
> preview mode of Qt designer?
Yes of course.
Andreas
--
[ signature omitted ]
Message 5 in thread
> No, I mean find a place on your form thats not occupied by any widget
> (that should select the form, visible in the object browser) and apply a
> layout to it. All you've done is creating a vertical layout that you can
> now move around on your dialog, unless its the dialogs layout it won't
> get resized with the dialog. So remove it and re-create it as I said
> above.
Ah!
If I use the Layout button on the left hand side in the Qt Designer Window
it has a different function than the one in Form -> Layout. I don't see
that "Form" layout anywhere in the object inspector, is that correct? I
guess, because now it seems to work. But what is the idea of that layout
compared to the "normal" layouts?
thanks!
--
[ signature omitted ]
Message 6 in thread
On 14.10.07 13:51:11, KH wrote:
>
> > No, I mean find a place on your form thats not occupied by any widget
> > (that should select the form, visible in the object browser) and apply a
> > layout to it. All you've done is creating a vertical layout that you can
> > now move around on your dialog, unless its the dialogs layout it won't
> > get resized with the dialog. So remove it and re-create it as I said
> > above.
>
> Ah!
>
> If I use the Layout button on the left hand side in the Qt Designer Window
> it has a different function than the one in Form -> Layout. I don't see
> that "Form" layout anywhere in the object inspector, is that correct?
Yes, if you want to remove it again, select the whole dialog and click
the "remove layout" button.
> I guess, because now it seems to work. But what is the idea of that
> layout compared to the "normal" layouts?
The ones from the widget box are not only layouts. You can see that when
you look into your .ui file with a text editor. The widget box layouts are
really a qwidget with a layout applied to it, while the buttons from the
toolbar allow you to set a layout on already existing widgets in your
dialog by just selecting them and then hitting the apropriate layout
button. This works without inserting another qwidget as layouts can be
nested directly.
Andreas
--
[ signature omitted ]