PDA

View Full Version : Expand and keep ratio



nifei
8th September 2009, 10:48
Hi.
How to make a widget expand both horizontally and vertically and keep the ratio width by height in the same time.
i mean, if i want the width / height is always 4/3, and occupy as more as possible space.

expected result:
case1: available width = 100, available height = 100, then the widget is expected to be 100 in width and 75 in height;
case2: available width = 100, available height = 60, then the widget should be 80-wide and 60-high.

Have i describe the issue clearly? Thanks in advance for any suggestion.

hkvm
8th September 2009, 16:19
Hi,

I never used this myself so I can't give an example, but I suspect QWidget::heightForWidth is what you're looking for. Reimplement this method in your widget to get the dimensions you want.