Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QSizePolicy Class Reference
[QtGui module]

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

 #include <QSizePolicy>

Public Types

Public Functions

Related Non-Members


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, and affects how the widget is treated by the layout engine. 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 QSizePolicy::Policy values 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 policies can be set in the constructor, and altered using the setHorizontalPolicy() and setVerticalPolicy() functions. The stretch factors can be set using the setHorizontalStretch() and setVerticalStretch() functions. The flag indicating whether the widget's sizeHint() is width-dependent (such as a menu bar or a word-wrapping label) can be set using the setHeightForWidth() function.

The current size policies and stretch factors be retrieved using the horizontalPolicy(), verticalPolicy(), horizontalStretch() and verticalStretch() functions. Alternatively, use the transpose() function to swap the horizontal and vertical policies and stretches. The hasHeightForWidth() function returns the current status of the flag indicating the size hint dependencies.

Use the expandingDirections() function to determine whether the associated widget can make use of more space than its sizeHint() function indicates, as well as find out in which directions it can expand.

Finally, the QSizePolicy class provides operators comparing this size policy to a given policy, as well as a QVariant operator storing this QSizePolicy as a QVariant object.

See also QSize, QWidget::sizeHint(), QWidget::sizePolicy(), and QLayoutItem::sizeHint().


Member Type Documentation

enum QSizePolicy::Policy

This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.

ConstantValueDescription
QSizePolicy::Fixed0The 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::MinimumGrowFlagThe 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). It cannot be smaller than the size provided by sizeHint().
QSizePolicy::MaximumShrinkFlagThe sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint().
QSizePolicy::PreferredGrowFlag | ShrinkFlagThe 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::ExpandingGrowFlag | ShrinkFlag | ExpandFlagThe 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::MinimumExpandingGrowFlag | ExpandFlagThe 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::IgnoredShrinkFlag | GrowFlag | IgnoreFlagThe sizeHint() is ignored. The widget will get as much space as possible.

See also PolicyFlag, setHorizontalPolicy(), and setVerticalPolicy().

enum QSizePolicy::PolicyFlag

These flags are combined together to form the various Policy values:

ConstantValueDescription
QSizePolicy::GrowFlag1The widget can grow beyond its size hint if necessary.
QSizePolicy::ExpandFlag2The widget should get as much space as possible.
QSizePolicy::ShrinkFlag4The widget can shrink below its size hint if necessary.
QSizePolicy::IgnoreFlag8The widget's size hint is ignored. The widget will get as much space as possible.

See also Policy.


Member Function Documentation

QSizePolicy::QSizePolicy ()

Constructs a QSizePolicy object with Fixed as its horizontal and vertical policies.

The policies can be altered using the setHorizontalPolicy() and setVerticalPolicy() functions. Use the setHeightForWidth() function if the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with line wrapping).

See also setHorizontalStretch() and setVerticalStretch().

QSizePolicy::QSizePolicy ( Policy horizontal, Policy vertical )

Constructs a QSizePolicy object with the given horizontal and vertical policies.

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 setHorizontalStretch() and setVerticalStretch().

Qt::Orientations QSizePolicy::expandingDirections () const

Returns whether a widget can make use of more space than the QWidget::sizeHint() function indicates.

A value of Qt::Horizontal or Qt::Vertical means that the widget can grow horizontally or vertically (i.e., the horizontal or vertical policy is Expanding or MinimumExpanding), whereas Qt::Horizontal | Qt::Vertical means that it can grow in both dimensions.

See also horizontalPolicy() and verticalPolicy().

bool QSizePolicy::hasHeightForWidth () const

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

See also setHeightForWidth().

Policy QSizePolicy::horizontalPolicy () const

Returns the horizontal component of the size policy.

See also setHorizontalPolicy(), verticalPolicy(), and horizontalStretch().

int QSizePolicy::horizontalStretch () const

Returns the horizontal stretch factor of the size policy.

See also setHorizontalStretch(), verticalStretch(), and horizontalPolicy().

void QSizePolicy::setHeightForWidth ( bool dependent )

Sets the flag determining whether the widget's preferred height depends on its width, to dependent.

See also hasHeightForWidth().

void QSizePolicy::setHorizontalPolicy ( Policy policy )

Sets the horizontal component to the given policy.

See also horizontalPolicy(), setVerticalPolicy(), and setHorizontalStretch().

void QSizePolicy::setHorizontalStretch ( uchar stretchFactor )

Sets the horizontal stretch factor of the size policy to the given stretchFactor.

See also horizontalStretch(), setVerticalStretch(), and setHorizontalPolicy().

void QSizePolicy::setVerticalPolicy ( Policy policy )

Sets the vertical component to the given policy.

See also verticalPolicy(), setHorizontalPolicy(), and setVerticalStretch().

void QSizePolicy::setVerticalStretch ( uchar stretchFactor )

Sets the vertical stretch factor of the size policy to the given stretchFactor.

See also verticalStretch(), setHorizontalStretch(), and setVerticalPolicy().

void QSizePolicy::transpose ()

Swaps the horizontal and vertical policies and stretches.

Policy QSizePolicy::verticalPolicy () const

Returns the vertical component of the size policy.

See also setVerticalPolicy(), horizontalPolicy(), and verticalStretch().

int QSizePolicy::verticalStretch () const

Returns the vertical stretch factor of the size policy.

See also setVerticalStretch(), horizontalStretch(), and verticalPolicy().

QSizePolicy::operator QVariant () const

Returns a QVariant storing this QSizePolicy.

bool QSizePolicy::operator!= ( const QSizePolicy & other ) const

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

See also operator==().

bool QSizePolicy::operator== ( const QSizePolicy & other ) const

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

See also operator!=().


Related Non-Members

QDataStream & operator<< ( QDataStream & stream, const QSizePolicy & policy )

This is an overloaded member function, provided for convenience.

Writes the size policy to the data stream stream.

This function was introduced in Qt 4.2.

See also Format of the QDataStream operators.

QDataStream & operator>> ( QDataStream & stream, QSizePolicy & policy )

This is an overloaded member function, provided for convenience.

Reads the size policy from the data stream stream.

This function was introduced in Qt 4.2.

See also Format of the QDataStream operators.


Member Type Documentation

enum QSizePolicy::ExpandData

Use the Qt::Orientations enum instead.

ConstantValueDescription
QSizePolicy::NoDirection0x0Use 0 instead.
QSizePolicy::Horizontally0x1Use Qt::Horizontal instead.
QSizePolicy::Vertically0x2Use Qt::Vertical instead.
QSizePolicy::BothDirections0x3Use Qt::Horizontal | Qt::Vertical instead.

typedef QSizePolicy::SizeType

Use the QSizePolicy::Policy enum instead.


Member Function Documentation

QSizePolicy::QSizePolicy ( Policy horizontal, Policy vertical, bool dependent )

Use the QSizePolicy() constructor and the setHeightForWidth() function instead.

For example, if you have code like

 QSizePolicy *policy = new QSizePolicy(horizontal, vertical, dependent);

you can rewrite it as

 QSizePolicy *policy = new QSizePolicy(horizontal, vertical);
 policy->setHeightForWidth(dependent);

QSizePolicy::QSizePolicy ( Policy horizontal, Policy vertical, uchar horizontalStretch, uchar verticalStretch, bool dependent = false )

Use the QSizePolicy() constructor and call the setHorizontalStretch(), setVerticalStretch(), and setHeightForWidth() functions instead.

For example, if you have code like

 QSizePolicy *policy = new QSizePolicy(horizontal, vertical,
                                                          horizontalStretch, verticalStretch,
                                                          dependent);

you can rewrite it as

 QSizePolicy *policy = new QSizePolicy(horizontal, vertical);
 policy->setHorizontalStretch(horizontalStretch);
 policy->setVerticalStretch(verticalStretch);
 policy->setHeightForWidth(dependent);

Qt::Orientations QSizePolicy::expanding () const

Use expandingDirections() instead.

Policy QSizePolicy::horData () const

Use horizontalPolicy() instead.

See also setHorData().

uint QSizePolicy::horStretch () const

Use horizontalStretch() instead.

See also setHorStretch().

bool QSizePolicy::mayGrowHorizontally () const

Use the horizontalPolicy() function combined with the QSizePolicy::PolicyFlag enum instead.

For example, if you have code like

 bool policy = mayGrowHorizontally();

you can rewrite it as

 bool policy = horizontalPolicy() & QSizePolicy::GrowFlag;

bool QSizePolicy::mayGrowVertically () const

Use the verticalPolicy() function combined with the QSizePolicy::PolicyFlag enum instead.

For example, if you have code like

 bool policy = mayGrowVertically();

you can rewrite it as

 bool policy = verticalPolicy() & QSizePolicy::GrowFlag;

bool QSizePolicy::mayShrinkHorizontally () const

Use the horizontalPolicy() function combined with the QSizePolicy::PolicyFlag enum instead.

For example, if you have code like

 bool policy = mayShrinkHorizontally();

you can rewrite it as

 bool policy = horizontalPolicy() & QSizePolicy::ShrinkFlag;

bool QSizePolicy::mayShrinkVertically () const

Use the verticalPolicy() function combined with the QSizePolicy::PolicyFlag enum instead.

For example, if you have code like

 bool policy = mayShrinkVertically();

you can rewrite it as

 bool policy = verticalPolicy() & QSizePolicy::ShrinkFlag;

void QSizePolicy::setHorData ( Policy policy )

Use setHorizontalPolicy() instead.

See also horData().

void QSizePolicy::setHorStretch ( uchar stretch )

Use setHorizontalStretch() instead.

See also horStretch().

void QSizePolicy::setVerData ( Policy policy )

Use setVerticalPolicy() instead.

See also verData().

void QSizePolicy::setVerStretch ( uchar stretch )

Use setVerticalStretch() instead.

See also verStretch().

Policy QSizePolicy::verData () const

Use verticalPolicy() instead.

See also setVerData().

uint QSizePolicy::verStretch () const

Use verticalStretch() instead.

See also setVerStretch().


Copyright © 2007 Trolltech Trademarks
Qt 4.2.3