PySide6.QtWidgets.QSizePolicy¶
- class QSizePolicy¶
- The - QSizePolicyclass is a layout attribute describing horizontal and vertical resizing policy. More…- Synopsis¶- Methods¶- def - __init__()
- def - controlType()
- def - __ne__()
- def - __eq__()
- def - setControlType()
- def - transpose()
- def - transposed()
- def - verticalPolicy()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - 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 - QSizePolicythat describes the horizontal and vertical resizing policy it prefers when being laid out. You can change this for a specific widget by changing its- sizePolicyproperty.- QSizePolicycontains two independent- Policyvalues 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 - QSizePolicyclass provides operators comparing this size policy to a given policy, as well as a QVariant operator storing this- QSizePolicyas a QVariant object.- See also - class PolicyFlag¶
- (inherits - enum.IntFlag) These flags are combined together to form the various- Policyvalues:- 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 
 - class 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 - QWidgetpolicy).- 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. 
 - class ControlType¶
- (inherits - enum.Flag) 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 - QDialogButtonBoxinstance.- QSizePolicy.CheckBox - A - QCheckBoxinstance.- QSizePolicy.ComboBox - A - QComboBoxinstance.- QSizePolicy.Frame - A - QFrameinstance.- QSizePolicy.GroupBox - A - QGroupBoxinstance.- QSizePolicy.Label - A - QLabelinstance.- QSizePolicy.Line - QSizePolicy.LineEdit - A - QLineEditinstance.- QSizePolicy.PushButton - A - QPushButtoninstance.- QSizePolicy.RadioButton - A - QRadioButtoninstance.- QSizePolicy.Slider - A - QAbstractSliderinstance.- QSizePolicy.SpinBox - A - QAbstractSpinBoxinstance.- QSizePolicy.TabWidget - A - QTabWidgetinstance.- QSizePolicy.ToolButton - A - QToolButtoninstance.- See also 
 - __init__()¶
 - Constructs a - QSizePolicyobject with- Fixedas 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- QLabelwith line wrapping).- __init__(horizontal, vertical[, type=QSizePolicy.ControlType.DefaultType])
- Parameters:
- horizontal – - Policy
- vertical – - Policy
- type – - ControlType
 
 
 - Constructs a - QSizePolicyobject with the given- horizontaland- verticalpolicies, 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- QLabelwith line wrapping).- controlType()¶
- Return type:
 
 - Returns the control type associated with the widget for which this size policy applies. - See also - expandingDirections()¶
- Return type:
- Combination of - Orientation
 
 - Returns whether a widget can make use of more space than the - 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 - Expandingor- MinimumExpanding), whereas Qt::Horizontal | Qt::Vertical means that it can grow in both dimensions.- See also - hasHeightForWidth()¶
- Return type:
- bool 
 
 - Returns - trueif the widget’s preferred height depends on its width; otherwise returns- false.- See also - hasWidthForHeight()¶
- Return type:
- bool 
 
 - Returns - trueif the widget’s width depends on its height; otherwise returns- false.- See also - Returns the horizontal component of the size policy. - horizontalStretch()¶
- Return type:
- int 
 
 - Returns the horizontal stretch factor of the size policy. - __ne__(s)¶
- Parameters:
- s – - QSizePolicy
- Return type:
- bool 
 
 - Returns - trueif this policy is different from- other; otherwise returns- false.- See also - operator==()- __eq__(s)¶
- Parameters:
- s – - QSizePolicy
- Return type:
- bool 
 
 - Returns - trueif this policy is equal to- other; otherwise returns- false.- See also - operator!=()- retainSizeWhenHidden()¶
- Return type:
- bool 
 
 - Returns whether the layout should retain the widget’s size when it is hidden. This is - falseby default.- See also - setControlType(type)¶
- Parameters:
- type – - ControlType
 
 - 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. - See also - setHeightForWidth(b)¶
- Parameters:
- b – bool 
 
 - Sets the flag determining whether the widget’s preferred height depends on its width, to - dependent.- See also - Sets the horizontal component to the given - policy.- setHorizontalStretch(stretchFactor)¶
- Parameters:
- stretchFactor – int 
 
 - Sets the horizontal stretch factor of the size policy to the given - stretchFactor.- stretchFactormust be in the range [0,255].- When two widgets are adjacent to each other in a horizontal layout, setting the horizontal stretch factor of the widget on the left to 2 and the factor of widget on the right to 1 will ensure that the widget on the left will always be twice the size of the one on the right. - setRetainSizeWhenHidden(retainSize)¶
- Parameters:
- retainSize – bool 
 
 - Sets whether a layout should retain the widget’s size when it is hidden. If - retainSizeis- true, the layout will not be changed by hiding the widget.- See also - Sets the vertical component to the given - policy.- setVerticalStretch(stretchFactor)¶
- Parameters:
- stretchFactor – int 
 
 - Sets the vertical stretch factor of the size policy to the given - stretchFactor.- stretchFactormust be in the range [0,255].- When two widgets are adjacent to each other in a vertical layout, setting the vertical stretch factor of the widget on the top to 2 and the factor of widget on the bottom to 1 will ensure that the widget on the top will always be twice the size of the one on the bottom. - setWidthForHeight(b)¶
- Parameters:
- b – bool 
 
 - Sets the flag determining whether the widget’s width depends on its height, to - dependent.- 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 - transpose()¶
 - Swaps the horizontal and vertical policies and stretches. - See also - transposed()¶
- Return type:
 
 - Returns a size policy object with the horizontal and vertical policies and stretches swapped. - See also - Returns the vertical component of the size policy. - verticalStretch()¶
- Return type:
- int 
 
 - Returns the vertical stretch factor of the size policy.