[Qt-interest] Aspect Ratio with QWidget::heightForWidth(int)
David Boddie
david.boddie at nokia.com
Wed Jul 22 17:06:17 CEST 2009
Huseyin Kozan wrote:
> On Wed, Jul 22, 2009 at 13:37, David Boddie <david.boddie at nokia.com>
> wrote:
> Is this sizeHint() thing for initial size ?
Yes. I thought it might influence the height-for-width behavior, but I was
mistaken. What you are doing should be correct. However, the height returned
by the heightForWidth() function is not treated as an absolute requirement
for the size of your widget - the layout won't push other widgets out of
the way to make room for your widget.
> But I cannot see the difference. What is the requirements for layouting
> parents and childs ? I mean we cannot force the main window to maintain
> the ratio, and do I need to add spacers near the promoted widget, and/or
> child widgets ?
You may be able to achieve something like what you want by giving your
widget a vertical size policy that lets it expand (Expanding) while giving
other widgets in the layout policies (or stretch factors) that ensure that
they stay out of the way. Even with these, the window's own size is a
constraint you can't override.
Another technique for ensuring that some content always has a particular
shape is to resize and position it within a widget. So, you look at how
much space you have and draw the desired shape, leaving the surrounding
area blank. There may be ways to ensure that a standard widget has a
certain shape, but that would require a bit more thought on my part.
David
--
David Boddie
Senior Technical Writer
Nokia, Qt Software
More information about the Qt-interest-old
mailing list