Qt Toolkit - QSizePolicy Class

| Classes - Annotated - Tree - Functions - Home - Structure

# QSizePolicy Class Reference

A layout attribute describing horizontal and vertical resizing. More...

`#include <qsizepolicy.h>`

List of all member functions.

## Public Members

- enum SizeType { Fixed = 0, Minimum = MayGrow, Maximum = MayShrink, Preferred = MayGrow|MayShrink, MinimumExpanding = Minimum|ExpMask, Expanding = MinimumExpanding|MayShrink }
- enum ExpandData { NoDirection = 0, Horizontal = 1, Vertical = 2, BothDirections = Horizontal | Vertical }
- QSizePolicy ()
- QSizePolicy ( SizeType hor, SizeType ver, bool hfw = FALSE )
- SizeType horData () const
- SizeType verData () const
- bool mayShrinkHorizontally () const
- bool mayShrinkVertically () const
- bool mayGrowHorizontally () const
- bool mayGrowVertically () const
- ExpandData expanding () const
- void setHorData ( SizeType d )
- void setVerData ( SizeType d )
- void setHeightForWidth ( bool b )
- bool hasHeightForWidth () const
- bool operator== ( const QSizePolicy & s ) const
- bool operator!= ( const QSizePolicy & s ) const

## Detailed Description

A layout attribute describing horizontal and vertical resizing.

The size policy of a widget is an expression of its willingness to be resized in various ways.

Widgets which reimplement QWidget::sizePolicy() return a QSizePolicy describing the horizontal and vertical resizing policy best used when laying out the widget. Only one of the constructors is of interest in most applications.

QSizePolicy contains two independent SizeType objects, one which describes the widgets's horizontal size policy and one which describes its vertical size policy, and it contains a flag to indicate whether the height and width of its preferred size are related.

The per-dimension SizeType objects are set in the usual constructor, and can be queried using a variety of functions, none of which are really interesting to application programmers.

The hasHeightForWidth() flag indicates whether the widget's sizeHint() is width-dependent (like a word-wrapping label).

See also QSizePolicy::SizeType.

Examples: xform/xform.cpp

## Member Type Documentation

### QSizePolicy::ExpandData

This enum type describes in which directions a widget can make use of extra space. There are four possible values:

- `NoDirection` - the widget cannot make us of extra space in any direction.
- `Horizontal` - the widget can usefully be wider than sizeHint() says.
- `Vertical` - the widget can usefully be taller than sizeHint() says.
- `BothDirections` - the widget can usefully be both wider and taller than sizeHint() says.

### QSizePolicy::SizeType

The per-dimension sizing types used when constructing a QSizePolicy are:

- `Fixed` - the sizeHint() is the only acceptable alternative, so widget can never grow or shrink (eg. the vertical direction of a pushbutton).
- `Minimum` - the sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (eg. the horizontal direction of a pushbutton).
- `Maximum` - the sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (eg. a separator line).
- `Preferred` - the sizeHint() is best, but the widget can be shrunk below that and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy).
- `MinimumExpanding` - the sizeHint() is a minimum. The widget can make use of extra space, so it should get as much space as possible (not currently used by any standard Qt widgets).
- `Expanding` - the sizeHint() is a sensible size, but the widget can be shrunk below that and still be useful. The widget can make use of extra space, so it should get as much space as possible (eg. the horizontal direction of a slider).

## Member Function Documentation

### QSizePolicy::QSizePolicy ()

Default constructor, produces a minimally initialized QSizePolicy.

### QSizePolicy::QSizePolicy ( SizeType hor, SizeType ver, bool hfw = FALSE )

This is the constructor normally used to return a value in the overridden QWidget::sizePolicy() function of a QWidget subclass.

It constructs a QSizePolicy with independent horizontal and vertical sizing types, hor and ver respectively. These sizing types affect how the widget is treated by the layout engine.

If hfw is TRUE, the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with automatic word-breaking).

### QSizePolicy::ExpandData QSizePolicy::expanding() const

Returns a value indicating if the widget can make use of extra space (ie. if it "wants" to grow) horizontally and/or vertically.

### bool QSizePolicy::hasHeightForWidth () const

Returns TRUE if the widget's preferred height depends on its width.

### QSizePolicy::SizeType QSizePolicy::horData() const

Returns the horizontal component of the size policy.

### bool QSizePolicy::mayGrowHorizontally () const

Returns TRUE if the widget can sensibly be wider than its sizeHint().

### bool QSizePolicy::mayGrowVertically () const

Returns TRUE if the widget can sensibly be taller than its sizeHint().

### bool QSizePolicy::mayShrinkHorizontally () const

Returns TRUE if the widget can sensibly be narrower than its sizeHint().

### bool QSizePolicy::mayShrinkVertically () const

Returns TRUE if the widget can sensibly be lower than its sizeHint().

### void QSizePolicy::setHeightForWidth ( bool b )

Sets the hasHeightForWidth() flag to b.

### void QSizePolicy::setHorData ( SizeType d )

Sets the horizontal component of the size policy to d.

### void QSizePolicy::setVerData ( SizeType d )

Sets the vertical component of the size policy to d.

### QSizePolicy::SizeType QSizePolicy::verData() const

Returns the vertical component of the size policy.

Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):

This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.