Qt-interest Archive, November 2007
easy way to proportionally scale a widget?
Message 1 in thread
Hi,
I would like to proportionally scale a (possibly complex) widget: for
example, if I have a dialog with 2 line-edits and a button, I would like
that when I increase the width of the dialog by 50%, the height also
increases by 50%, so that the resized dialog is a zoomed-in version of
the original. In particular, I want the height of the line-edits to change.
Is there an easy way to achieve that results?
Thank you,
Nicolas
--
[ signature omitted ]
Message 2 in thread
On torsdag den 29. November 2007, nicolas wrote:
> I would like to proportionally scale a (possibly complex) widget: for
> example, if I have a dialog with 2 line-edits and a button, I would like
> that when I increase the width of the dialog by 50%, the height also
> increases by 50%, so that the resized dialog is a zoomed-in version of
> the original. In particular, I want the height of the line-edits to change.
> Is there an easy way to achieve that results?
An easy way? Well...
First of all, you need to set the size policy on your line edits. They are
vertically fixed, and you need to set them to MinimumExpanding. This will
allow them to grow vertically.
Second, you need to implement widthForHeight(int) in your complex widget and
just return the same number. Like this:
int MyWidget::heightForWidth(int w) const {
// Ask the layout manager to make the widget square (in pixels)
return w;
}
More advanced would be to figure out the pixel dimensions on the current
screen (they might not be square) and adjust the returned number to something
that makes the widget square on the screen instead of in pixels.
You also need to tell Qt to use this by setting a size policy on your widget
where you did setHeightForWidth(true).
You need to do a bit of reading in assistant to truly understand these tricks.
Searching for setHeightForWidth, heightForWidth, QSizePolicy, and
QDesktopWidget should give you all the necessary knowledge.
I hope this helps,
Bo.
--
[ signature omitted ]
Message 3 in thread
Nicolas wrote:
> I would like to proportionally scale a (possibly complex) widget: for
> example, if I have a dialog with 2 line-edits and a button, I
> would like
> that when I increase the width of the dialog by 50%, the height also
> increases by 50%, so that the resized dialog is a zoomed-in
> version of
> the original. In particular, I want the height of the
> line-edits to change.
> Is there an easy way to achieve that results?
One possibility would be this:
http://labs.trolltech.com/blogs/2007/11/22/widgets-on-the-canvas-integra
ted/
The problem with this is, until Qt 4.4 is released (next spring?) you'll
have to use the snapshots.
Not sure how stable they are right now.
Cheers,
Peter
--
[ signature omitted ]