PDA

View Full Version : Fixed-height layout question



TheJim01
12th March 2010, 17:11
I have what I think is probably a simple problem with my layout, but I can't figure out what I'm doing wrong. I'm using designer, so the code is generated, but I can provide it if necessary.

I have a custom widget, which is designed to scale its self gracefully, and works well when stretching (you can use the generic "Widget" widget, if you want to try to replicate my problem). Below it, I have a horizontal spacer, a label, a fixed-width spin box, and another horizontal spacer. To keep the label and spin box centered, I grouped them and the spacers into a QHBoxLayout.

Me desired behavior is: My custom widget should expand as necessary, and the spin box layout should remain the same height. At first I grouped the widget and the spin box layout into a QVBoxLayout--oops! I realized my mistake, and grouped them into a vertical QSplitter instead.

The QSplitter works mostly as expected, but when stretching vertically, there comes a point there the spin box layout starts to stretch vertically--the child widgets don't stretch, just the layout its self.

As I said, I'd like the only child element doing any vertical expansion to be the custom widget. Can I somehow set the height of the spin box layout to a fixed dimension, or should I group them with something else?

Thanks!

JohannesMunk
16th March 2010, 20:37
You just need to set the Vertical Stretch (in Property-Editor QWidget.sizePolicy.Vertical Stretch) of your custom-Widget to 1, and the one of your QHBoxLayout to 0.

Stretch: http://doc.trolltech.com/4.6/layout.html#stretch-factors . The remaining available space is divided proportional to the stretchfactors.

Then you should also use a QVBoxLayout, as in your case the SpinBoxCell should never get a bigger height, and thus the user shall not be able to change it by means of a splitter.

HIH

Johannes