QSizePolicy

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

Inheritance diagram of PySide6.QtWidgets.QSizePolicy

Synopsis

Functions

Detailed Description

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 . 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 sizePolicy property.

QSizePolicy contains two independent 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 and functions. The stretch factors can be set using the and 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 function.

The current size policies and stretch factors be retrieved using the , , and functions. Alternatively, use the function to swap the horizontal and vertical policies and stretches. The function returns the current status of the flag indicating the size hint dependencies.

Use the 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.

class PySide6.QtWidgets.QSizePolicy

PySide6.QtWidgets.QSizePolicy(horizontal, vertical[, type=DefaultType])

Parameters
PySide6.QtWidgets.QSizePolicy.PolicyFlag

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

Constant

Description

QSizePolicy.GrowFlag

The widget can grow beyond its size hint if necessary.

QSizePolicy.ExpandFlag

The widget should get as much space as possible.

QSizePolicy.ShrinkFlag

The widget can shrink below its size hint if necessary.

QSizePolicy.IgnoreFlag

The widget’s size hint is ignored. The widget will get as much space as possible.

See also

Policy

PySide6.QtWidgets.QSizePolicy.Policy

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

Constant

Description

QSizePolicy.Fixed

The 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). It cannot be smaller than the size provided by sizeHint().

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). It cannot be larger than the size provided by sizeHint().

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 horizontal 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 horizontal slider).

QSizePolicy.Ignored

The sizeHint() is ignored. The widget will get as much space as possible.

See also

PolicyFlag setHorizontalPolicy()setVerticalPolicy()

PySide6.QtWidgets.QSizePolicy.ControlType

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

Constant

Description

QSizePolicy.DefaultType

The default type, when none is specified.

QSizePolicy.ButtonBox

A QDialogButtonBox instance.

QSizePolicy.CheckBox

A QCheckBox instance.

QSizePolicy.ComboBox

A QComboBox instance.

QSizePolicy.Frame

A QFrame instance.

QSizePolicy.GroupBox

A QGroupBox instance.

QSizePolicy.Label

A QLabel instance.

QSizePolicy.Line

A QFrame instance with HLine or VLine .

QSizePolicy.LineEdit

A QLineEdit instance.

QSizePolicy.PushButton

A QPushButton instance.

QSizePolicy.RadioButton

A QRadioButton instance.

QSizePolicy.Slider

A QAbstractSlider instance.

QSizePolicy.SpinBox

A QAbstractSpinBox instance.

QSizePolicy.TabWidget

A QTabWidget instance.

QSizePolicy.ToolButton

A QToolButton instance.

PySide6.QtWidgets.QSizePolicy.controlType()
Return type

ControlType

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

See also

setControlType()

PySide6.QtWidgets.QSizePolicy.expandingDirections()
Return type

Orientations

PySide6.QtWidgets.QSizePolicy.hasHeightForWidth()
Return type

bool

PySide6.QtWidgets.QSizePolicy.hasWidthForHeight()
Return type

bool

PySide6.QtWidgets.QSizePolicy.horizontalPolicy()
Return type

Policy

PySide6.QtWidgets.QSizePolicy.horizontalStretch()
Return type

int

PySide6.QtWidgets.QSizePolicy.__ne__(s)
Parameters

sPySide6.QtWidgets.QSizePolicy

Return type

bool

PySide6.QtWidgets.QSizePolicy.__eq__(s)
Parameters

sPySide6.QtWidgets.QSizePolicy

Return type

bool

PySide6.QtWidgets.QSizePolicy.retainSizeWhenHidden()
Return type

bool

PySide6.QtWidgets.QSizePolicy.setControlType(type)
Parameters

typeControlType

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 macOS Aqua guidelines specify that push buttons should be separated by 12 pixels, whereas vertically stacked radio buttons only require 6 pixels.

PySide6.QtWidgets.QSizePolicy.setHeightForWidth(b)
Parameters

b – bool

PySide6.QtWidgets.QSizePolicy.setHorizontalPolicy(d)
Parameters

dPolicy

PySide6.QtWidgets.QSizePolicy.setHorizontalStretch(stretchFactor)
Parameters

stretchFactor – int

PySide6.QtWidgets.QSizePolicy.setRetainSizeWhenHidden(retainSize)
Parameters

retainSize – bool

PySide6.QtWidgets.QSizePolicy.setVerticalPolicy(d)
Parameters

dPolicy

PySide6.QtWidgets.QSizePolicy.setVerticalStretch(stretchFactor)
Parameters

stretchFactor – int

PySide6.QtWidgets.QSizePolicy.setWidthForHeight(b)
Parameters

b – bool

PySide6.QtWidgets.QSizePolicy.transpose()
PySide6.QtWidgets.QSizePolicy.transposed()
Return type

PySide6.QtWidgets.QSizePolicy

PySide6.QtWidgets.QSizePolicy.verticalPolicy()
Return type

Policy

PySide6.QtWidgets.QSizePolicy.verticalStretch()
Return type

int