CopperSpice API  1.9.2
QSizePolicy Class Reference

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

Public Typedefs

using ControlTypes = QFlags< ControlType >
 

Public Types

enum  ControlType
 
enum  Policy
 
enum  PolicyFlag
 

Public Methods

 QSizePolicy ()
 
 QSizePolicy (Policy horizontal, Policy vertical, ControlType type=DefaultType)
 
ControlType controlType () const
 
Qt::Orientations expandingDirections () const
 
bool hasHeightForWidth () const
 
bool hasWidthForHeight () const
 
Policy horizontalPolicy () const
 
int horizontalStretch () const
 
 operator QVariant () const
 
bool operator!= (const QSizePolicy &other) const
 
bool operator== (const QSizePolicy &other) const
 
bool retainSizeWhenHidden () const
 
void setControlType (ControlType type)
 
void setHeightForWidth (bool isHeightForWidth)
 
void setHorizontalPolicy (Policy policy)
 
void setHorizontalStretch (int stretchFactor)
 
void setRetainSizeWhenHidden (bool retainSize)
 
void setVerticalPolicy (Policy policy)
 
void setVerticalStretch (int stretchFactor)
 
void setWidthForHeight (bool isWidthForHeight)
 
void transpose ()
 
Policy verticalPolicy () const
 
int verticalStretch () const
 

Friends

QDataStreamoperator<< (QDataStream &stream, const QSizePolicy &policy)
 
QDataStreamoperator>> (QDataStream &stream, QSizePolicy &policy)
 

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 management. Each widget returns a QSizePolicy that describes the horizontal and vertical resizing policy it prefers when being laid out. You can change this for a specific widget by changing its QWidget::sizePolicy property.

QSizePolicy contains two independent QSizePolicy::Policy values and two stretch factors; one describes the widget'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() methods. The stretch factors can be set using the setHorizontalStretch() and setVerticalStretch() methods. 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() method.

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

Use the expandingDirections() method to determine whether the associated widget can make use of more space than its sizeHint() method 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, QLayoutItem::sizeHint()

Member Typedef Documentation

Typedef for QFlags<ControlType> which contains an OR combination of ControlType values.

Refer to QSizePolicy::ControlType for the enum documentation.

Member Enumeration Documentation

This enum specifies the different types of widgets in terms of layout interaction.

ConstantValueDescription
QSizePolicy::DefaultType 0x00000001 The default type, when none is specified.
QSizePolicy::ButtonBox 0x00000002 QDialogButtonBox instance.
QSizePolicy::CheckBox 0x00000004 QCheckBox instance.
QSizePolicy::ComboBox 0x00000008 QComboBox instance.
QSizePolicy::Frame 0x00000010 QFrame instance.
QSizePolicy::GroupBox 0x00000020 QGroupBox instance.
QSizePolicy::Label 0x00000040 QLabel instance.
QSizePolicy::Line 0x00000080 QFrame instance with QFrame::HLine or QFrame::VLine.
QSizePolicy::LineEdit 0x00000100 QLineEdit instance.
QSizePolicy::PushButton 0x00000200 QPushButton instance.
QSizePolicy::RadioButton 0x00000400 QRadioButton instance.
QSizePolicy::Slider 0x00000800 QAbstractSlider instance.
QSizePolicy::SpinBox 0x00001000 QAbstractSpinBox instance.
QSizePolicy::TabWidget 0x00002000 QTabWidget instance.
QSizePolicy::ToolButton 0x00004000 QToolButton instance.
See also
setControlType(), controlType()

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

ConstantValueDescription
QSizePolicy::Fixed 0x0 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 0x1 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). It can not be smaller than the size provided by sizeHint().
QSizePolicy::Maximum 0x4 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). It can not be larger than the size provided by sizeHint().
QSizePolicy::Preferred 0x5 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 0x7 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 horizontal slider).
QSizePolicy::MinimumExpanding 0x3 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 horizontal slider).
QSizePolicy::Ignored 0xD The sizeHint() is ignored. The widget will get as much space as possible.
See also
PolicyFlag, setHorizontalPolicy(), setVerticalPolicy()

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

ConstantValueDescription
QSizePolicy::GrowFlag 0x1Can grow beyond its size hint if necessary.
QSizePolicy::ExpandFlag 0x2Widget should get as much space as possible.
QSizePolicy::ShrinkFlag 0x4Widget can shrink below its size hint if necessary.
QSizePolicy::IgnoreFlag 0x8Widget's size hint is ignored. The widget will get as much space as possible.
See also
Policy

Constructor & Destructor Documentation

QSizePolicy::QSizePolicy ( )
inline

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(), setVerticalStretch()
QSizePolicy::QSizePolicy ( Policy  horizontal,
Policy  vertical,
ControlType  type = DefaultType 
)
inline

Constructs a QSizePolicy object with the given horizontal and vertical policies, and the specified control type.

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(), setVerticalStretch(), controlType()

Method Documentation

ControlType QSizePolicy::controlType ( ) const

Returns the control type associated with the widget for which this size policy applies.

See also
setControlType()
Qt::Orientations QSizePolicy::expandingDirections ( ) const
inline

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(), verticalPolicy()
bool QSizePolicy::hasHeightForWidth ( ) const
inline

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

See also
setHeightForWidth()
bool QSizePolicy::hasWidthForHeight ( ) const
inline

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

See also
setWidthForHeight()
Policy QSizePolicy::horizontalPolicy ( ) const
inline

Returns the horizontal component of the size policy.

See also
setHorizontalPolicy(), verticalPolicy(), horizontalStretch()
int QSizePolicy::horizontalStretch ( ) const
inline

Returns the horizontal stretch factor of the size policy.

See also
setHorizontalStretch(), verticalStretch(), horizontalPolicy()
QSizePolicy::operator QVariant ( ) const

Returns a QVariant storing this QSizePolicy.

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

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

See also
operator==()
bool QSizePolicy::operator== ( const QSizePolicy &  other) const
inline

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

See also
operator!=()
bool QSizePolicy::retainSizeWhenHidden ( ) const
inline

Returns the value of the property.

void QSizePolicy::setControlType ( ControlType  type)

Sets the control type associated with the widget for which this size policy applies to type.

The control type specifies the type of the widget for which this size policy applies. It is used by some styles, notably QMacStyle, to insert proper spacing between widgets. For example, the Mac OS X Aqua guidelines specify that push buttons should be separated by 12 pixels, whereas vertically stacked radio buttons only require 6 pixels.

See also
controlType(), QStyle::layoutSpacing()
void QSizePolicy::setHeightForWidth ( bool  isHeightForWidth)
inline

Sets isHeightForWidth to indicate whether the widget's preferred height depends on its width.

See also
hasHeightForWidth(), setWidthForHeight()
void QSizePolicy::setHorizontalPolicy ( Policy  policy)
inline

Sets the horizontal component to the given policy.

See also
horizontalPolicy(), setVerticalPolicy(), setHorizontalStretch()
void QSizePolicy::setHorizontalStretch ( int  stretchFactor)
inline

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

See also
horizontalStretch(), setVerticalStretch(), setHorizontalPolicy()
void QSizePolicy::setRetainSizeWhenHidden ( bool  retainSize)
inline

Sets the value of the property to retainSize.

void QSizePolicy::setVerticalPolicy ( Policy  policy)
inline

Sets the vertical component to the given policy.

See also
verticalPolicy(), setHorizontalPolicy(), setVerticalStretch()
void QSizePolicy::setVerticalStretch ( int  stretchFactor)
inline

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

See also
verticalStretch(), setHorizontalStretch(), setVerticalPolicy()
void QSizePolicy::setWidthForHeight ( bool  isWidthForHeight)
inline

Sets isWidthForHeigh to indicate whether the widget's preferred width depends on its height.

This is only supported for QGraphicsLayout's subclasses. It is not possible to have a layout with both height-for-width and width-for-height constraints at the same time.

See also
hasWidthForHeight(), setHeightForWidth()
void QSizePolicy::transpose ( )
inline

Swaps the horizontal and vertical policies and stretches.

Policy QSizePolicy::verticalPolicy ( ) const
inline

Returns the vertical component of the size policy.

See also
setVerticalPolicy(), horizontalPolicy(), verticalStretch()
int QSizePolicy::verticalStretch ( ) const
inline

Returns the vertical stretch factor of the size policy.

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

Friends And Related Function Documentation

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

Writes the size policy to the data stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.

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

Reads the size policy from the data stream and returns a reference to the stream.

Refer to Serializing Data Types for additional information.