Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QSizePolicy Class Reference

The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy. More...

    #include <QSizePolicy>

- List of all members, including inherited members
- Compatibility members

### Public Types

- enum ExpandData { NoDirection, Horizontally, Vertically, BothDirections }
- typedef SizeType
- enum SizeTypeFlag { Fixed, Minimum, Maximum, Preferred, Expanding, ..., Ignored }

### Public Functions

- QSizePolicy ()
- QSizePolicy ( SizeType hor, SizeType ver )
- ExpandData expanding () const
- bool hasHeightForWidth () const
- SizeType horizontalData () const
- uint horizontalStretch () const
- bool mayGrowHorizontally () const
- bool mayGrowVertically () const
- bool mayShrinkHorizontally () const
- bool mayShrinkVertically () const
- void setHeightForWidth ( bool b )
- void setHorizontalData ( SizeType d )
- void setHorizontalStretch ( uchar sf )
- void setVerticalData ( SizeType d )
- void setVerticalStretch ( uchar sf )
- void transpose ()
- SizeType verticalData () const
- uint verticalStretch () const
- bool operator!= ( const QSizePolicy & s ) const
- bool operator== ( const QSizePolicy & s ) const

## Detailed Description

The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.

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

Widgets that reimplement QWidget::sizePolicy() return a QSizePolicy that describes the horizontal and vertical resizing policy they prefer when being laid out.

QSizePolicy contains two independent SizeType objects and two stretch factors; one describes the widgets's horizontal size policy, and the other describes its vertical size policy. It also contains a flag to indicate whether the height and width of its preferred size are related.

The horizontal and vertical SizeTypes are set in the usual constructor and can be queried using a variety of functions.

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

See also QSizePolicy::SizeType.

## Member Type Documentation

### enum QSizePolicy::ExpandData

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

`QSizePolicy::NoDirection` | the widget cannot make use of extra space in any direction.
`QSizePolicy::Horizontally` | the widget can usefully be wider than the sizeHint().
`QSizePolicy::Vertically` | the widget can usefully be taller than the sizeHint().
`QSizePolicy::BothDirections` | the widget can usefully be both wider and taller than the sizeHint().

### enum QSizePolicy::SizeTypeFlag
typedef QSizePolicy::SizeType

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

`QSizePolicy::Fixed` | the QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
`QSizePolicy::Minimum` | the sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button).
`QSizePolicy::Maximum` | the sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line).
`QSizePolicy::Preferred` | the sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy).
`QSizePolicy::Expanding` | the sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a slider).
`QSizePolicy::MinimumExpanding` | the sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a slider).
`QSizePolicy::Ignored` | the sizeHint() is ignored. The widget will get as much space as possible.

The SizeType typedef can store a combination of SizeTypeFlag values.

## Member Function Documentation

### QSizePolicy::QSizePolicy ()

Constructs a minimally initialized QSizePolicy.

### QSizePolicy::QSizePolicy ( SizeType hor, SizeType ver )

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.

Use setHeightForWidth() if the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with line wrapping).

See also horizontalData(), verticalData(), and setHeightForWidth().

### ExpandData QSizePolicy::expanding () const

Returns whether this layout can make use of more space than sizeHint(). A value of `Qt::Vertical` or `Qt::Horizontal` means that it wants to grow in only one dimension, whereas `BothDirections` means that it wants to grow in both dimensions.

mayShrinkVertically() mayGrowVertically()

See also mayShrinkHorizontally() and mayGrowHorizontally().

### bool QSizePolicy::hasHeightForWidth () const

Returns true if the widget's preferred height depends on its width; otherwise returns false.

See also setHeightForWidth().

### SizeType QSizePolicy::horizontalData () const

Returns the horizontal component of the size policy.

See also setHorizontalData(), verticalData(), and horizontalStretch().

### uint QSizePolicy::horizontalStretch () const

Returns the horizontal stretch factor of the size policy.

See also setHorizontalStretch() and verticalStretch().

### bool QSizePolicy::mayGrowHorizontally () const

Returns true if the widget can sensibly be wider than its sizeHint(); otherwise returns false.

See also mayGrowVertically() and mayShrinkHorizontally().

### bool QSizePolicy::mayGrowVertically () const

Returns true if the widget can sensibly be taller than its sizeHint(); otherwise returns false.

See also mayGrowHorizontally() and mayShrinkVertically().

### bool QSizePolicy::mayShrinkHorizontally () const

Returns true if the widget can sensibly be narrower than its sizeHint(); otherwise returns false.

See also mayShrinkVertically() and mayGrowHorizontally().

### bool QSizePolicy::mayShrinkVertically () const

Returns true if the widget can sensibly be shorter than its sizeHint(); otherwise returns false.

See also mayShrinkHorizontally() and mayGrowVertically().

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

Sets the hasHeightForWidth() flag to b.

See also hasHeightForWidth().

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

Sets the horizontal component of the size policy to size type d.

See also horizontalData() and setVerticalData().

### void QSizePolicy::setHorizontalStretch ( uchar sf )

Sets the horizontal stretch factor of the size policy to sf.

See also horizontalStretch() and setVerticalStretch().

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

Sets the vertical component of the size policy to size type d.

See also verticalData() and setHorizontalData().

### void QSizePolicy::setVerticalStretch ( uchar sf )

Sets the vertical stretch factor of the size policy to sf.

See also verticalStretch() and setHorizontalStretch().

### void QSizePolicy::transpose ()

Swaps the horizontal and vertical policies and stretches.

### SizeType QSizePolicy::verticalData () const

Returns the vertical component of the size policy.

See also setVerticalData(), horizontalData(), and verticalStretch().

### uint QSizePolicy::verticalStretch () const

Returns the vertical stretch factor of the size policy.

See also setVerticalStretch() and horizontalStretch().

### bool QSizePolicy::operator!= ( const QSizePolicy & s ) const

Returns true if this policy is different from s; otherwise returns false.

See also operator==().

### bool QSizePolicy::operator== ( const QSizePolicy & s ) const

Returns true if this policy is equal to s; otherwise returns false.

See also operator!=().