PySide.QtGui.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 . Each widget returns a PySide.QtGui.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 特性。
PySide.QtGui.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 PySide.QtGui.QSizePolicy.setHorizontalPolicy() and PySide.QtGui.QSizePolicy.setVerticalPolicy() functions. The stretch factors can be set using the PySide.QtGui.QSizePolicy.setHorizontalStretch() and PySide.QtGui.QSizePolicy.setVerticalStretch() functions. The flag indicating whether the widget's PySide.QtGui.QWidget.sizeHint() is width-dependent (such as a menu bar or a word-wrapping label) can be set using the PySide.QtGui.QSizePolicy.setHeightForWidth() 函数。
The current size policies and stretch factors be retrieved using the PySide.QtGui.QSizePolicy.horizontalPolicy() , PySide.QtGui.QSizePolicy.verticalPolicy() , PySide.QtGui.QSizePolicy.horizontalStretch() and PySide.QtGui.QSizePolicy.verticalStretch() functions. Alternatively, use the PySide.QtGui.QSizePolicy.transpose() function to swap the horizontal and vertical policies and stretches. The PySide.QtGui.QSizePolicy.hasHeightForWidth() function returns the current status of the flag indicating the size hint dependencies.
使用 PySide.QtGui.QSizePolicy.expandingDirections() function to determine whether the associated widget can make use of more space than its PySide.QtGui.QWidget.sizeHint() function indicates, as well as find out in which directions it can expand.
Finally, the PySide.QtGui.QSizePolicy class provides operators comparing this size policy to a given policy, as well as a PySide.QtCore.QVariant operator storing this PySide.QtGui.QSizePolicy 作为 PySide.QtCore.QVariant 对象。
| 参数: |
|
|---|
构造 PySide.QtGui.QSizePolicy object with Fixed as its horizontal and vertical policies.
The policies can be altered using the PySide.QtGui.QSizePolicy.setHorizontalPolicy() and PySide.QtGui.QSizePolicy.setVerticalPolicy() functions. Use the PySide.QtGui.QSizePolicy.setHeightForWidth() function if the preferred height of the widget is dependent on the width of the widget (for example, a PySide.QtGui.QLabel with line wrapping).
构造 PySide.QtGui.QSizePolicy 对象采用给定 horizontal and vertical policies, and DefaultType as the control type.
使用 PySide.QtGui.QSizePolicy.setHeightForWidth() if the preferred height of the widget is dependent on the width of the widget (for example, a PySide.QtGui.QLabel with line wrapping).
构造 PySide.QtGui.QSizePolicy 对象采用给定 horizontal and vertical policies, and the specified control type .
使用 PySide.QtGui.QSizePolicy.setHeightForWidth() if the preferred height of the widget is dependent on the width of the widget (for example, a PySide.QtGui.QLabel with line wrapping).
此枚举指定 Widget 的不同类型,就布局交互而言:
| 常量 | 描述 |
|---|---|
| QSizePolicy.DefaultType | The default type, when none is specified. |
| QSizePolicy.ButtonBox | A PySide.QtGui.QDialogButtonBox 实例。 |
| QSizePolicy.CheckBox | A PySide.QtGui.QCheckBox 实例。 |
| QSizePolicy.ComboBox | A PySide.QtGui.QComboBox 实例。 |
| QSizePolicy.Frame | A PySide.QtGui.QFrame 实例。 |
| QSizePolicy.GroupBox | A PySide.QtGui.QGroupBox 实例。 |
| QSizePolicy.Label | A PySide.QtGui.QLabel 实例。 |
| QSizePolicy.Line | A PySide.QtGui.QFrame 实例与 QFrame.HLine or QFrame.VLine . |
| QSizePolicy.LineEdit | A PySide.QtGui.QLineEdit 实例。 |
| QSizePolicy.PushButton | A PySide.QtGui.QPushButton 实例。 |
| QSizePolicy.RadioButton | A PySide.QtGui.QRadioButton 实例。 |
| QSizePolicy.Slider | A PySide.QtGui.QAbstractSlider 实例。 |
| QSizePolicy.SpinBox | A PySide.QtGui.QAbstractSpinBox 实例。 |
| QSizePolicy.TabWidget | A PySide.QtGui.QTabWidget 实例。 |
| QSizePolicy.ToolButton | A PySide.QtGui.QToolButton 实例。 |
These flags are combined together to form the various QSizePolicy.Policy 值:
| 常量 | 描述 |
|---|---|
| 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. |
另请参阅
QSizePolicy.Policy
This enum describes the various per-dimension sizing types used when constructing a PySide.QtGui.QSizePolicy .
| 常量 | 描述 |
|---|---|
| QSizePolicy.Fixed | 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 | 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 | 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 | 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 PySide.QtGui.QWidget policy). |
| QSizePolicy.Expanding | 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 | 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 | sizeHint() is ignored. The widget will get as much space as possible. |
另请参阅
QSizePolicy.PolicyFlag PySide.QtGui.QSizePolicy.setHorizontalPolicy() PySide.QtGui.QSizePolicy.setVerticalPolicy()
| 返回类型: | PySide.QtGui.QSizePolicy.ControlType |
|---|
Returns the control type associated with the widget for which this size policy applies.
| 返回类型: | PySide.QtCore.Qt.Orientations |
|---|
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.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the widget's preferred height depends on its width; otherwise returns false.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the widget's width depends on its height; otherwise returns false.
| 返回类型: | PySide.QtGui.QSizePolicy.Policy |
|---|
Returns the horizontal component of the size policy.
| 返回类型: | PySide.QtCore.int |
|---|
Returns the horizontal stretch factor of the size policy.
| 参数: | s – PySide.QtGui.QSizePolicy |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if this policy is different from other ;否则返回 false。
另请参阅
PySide.QtGui.QSizePolicy.operator==()
| 参数: | s – PySide.QtGui.QSizePolicy |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if this policy is equal to other ;否则返回 false。
另请参阅
PySide.QtGui.QSizePolicy.operator!=()
| 参数: | type – PySide.QtGui.QSizePolicy.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 PySide.QtGui.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.
| 参数: | b – PySide.QtCore.bool |
|---|
Sets the flag determining whether the widget's preferred height depends on its width, to dependent .
| 参数: | d – PySide.QtGui.QSizePolicy.Policy |
|---|
Sets the horizontal component to the given policy .
| 参数: | stretchFactor – PySide.QtCore.uchar |
|---|
Sets the horizontal stretch factor of the size policy to the given stretchFactor .
| 参数: | d – PySide.QtGui.QSizePolicy.Policy |
|---|
Sets the vertical component to the given policy .
| 参数: | stretchFactor – PySide.QtCore.uchar |
|---|
Sets the vertical stretch factor of the size policy to the given stretchFactor .
| 参数: | b – PySide.QtCore.bool |
|---|
Sets the flag determining whether the widget's width depends on its height, to dependent .
This is only supported for PySide.QtGui.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.
Swaps the horizontal and vertical policies and stretches.
| 返回类型: | PySide.QtGui.QSizePolicy.Policy |
|---|
返回尺寸策略的垂直组件。
| 返回类型: | PySide.QtCore.int |
|---|
返回尺寸策略的垂直拉伸因子。