The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy. 更多...
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 . 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 特性。
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 () 函数。
The current size policies and stretch factors be retrieved using the horizontalPolicy (), verticalPolicy (), horizontalStretch () 和 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.
使用 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 对象。
This enum specifies the different types of widgets in terms of layout interaction:
| 常量 | 值 | 描述 |
|---|---|---|
| QSizePolicy.DefaultType | 0x00000001 | The default type, when none is specified. |
| QSizePolicy.ButtonBox | 0x00000002 | A QDialogButtonBox 实例。 |
| QSizePolicy.CheckBox | 0x00000004 | A QCheckBox 实例。 |
| QSizePolicy.ComboBox | 0x00000008 | A QComboBox 实例。 |
| QSizePolicy.Frame | 0x00000010 | A QFrame 实例。 |
| QSizePolicy.GroupBox | 0x00000020 | A QGroupBox 实例。 |
| QSizePolicy.Label | 0x00000040 | A QLabel 实例。 |
| QSizePolicy.Line | 0x00000080 | A QFrame instance with QFrame.HLine or QFrame.VLine . |
| QSizePolicy.LineEdit | 0x00000100 | A QLineEdit 实例。 |
| QSizePolicy.PushButton | 0x00000200 | A QPushButton 实例。 |
| QSizePolicy.RadioButton | 0x00000400 | A QRadioButton 实例。 |
| QSizePolicy.Slider | 0x00000800 | A QAbstractSlider 实例。 |
| QSizePolicy.SpinBox | 0x00001000 | A QAbstractSpinBox 实例。 |
| QSizePolicy.TabWidget | 0x00002000 | A QTabWidget 实例。 |
| QSizePolicy.ToolButton | 0x00004000 | A QToolButton 实例。 |
该枚举在 Qt 4.3 引入或被修改。
The ControlTypes type is a typedef for QFlags <ControlType>. It stores an OR combination of ControlType values.
另请参阅 setControlType () 和 controlType ().
This enum describes the various per-dimension sizing types used when constructing a QSizePolicy .
| 常量 | 值 | 描述 |
|---|---|---|
| QSizePolicy.Fixed | 0 | 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 | GrowFlag | 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 | ShrinkFlag | 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 | GrowFlag | ShrinkFlag | 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 | GrowFlag | ShrinkFlag | ExpandFlag | 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 | GrowFlag | ExpandFlag | 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 | ShrinkFlag | GrowFlag | IgnoreFlag | The sizeHint() is ignored. The widget will get as much space as possible. |
另请参阅 PolicyFlag , setHorizontalPolicy (), and setVerticalPolicy ().
These flags are combined together to form the various Policy 值:
| 常量 | 值 | 描述 |
|---|---|---|
| QSizePolicy.GrowFlag | 1 | The widget can grow beyond its size hint if necessary. |
| QSizePolicy.ExpandFlag | 2 | The widget should get as much space as possible. |
| QSizePolicy.ShrinkFlag | 4 | The widget can shrink below its size hint if necessary. |
| QSizePolicy.IgnoreFlag | 8 | The widget's size hint is ignored. The widget will get as much space as possible. |
另请参阅 Policy .
构造 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).
另请参阅 setHorizontalStretch () and setVerticalStretch ().
构造 QSizePolicy object with the given horizontal and vertical policies, and DefaultType 作为 control type.
使用 setHeightForWidth () if the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with line wrapping).
另请参阅 setHorizontalStretch () and setVerticalStretch ().
构造 QSizePolicy object with the given horizontal and vertical policies, and the specified control type .
使用 setHeightForWidth () if the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with line wrapping).
该函数在 Qt 4.3 引入。
另请参阅 setHorizontalStretch (), setVerticalStretch (),和 controlType ().
Returns the control type associated with the widget for which this size policy applies.
该函数在 Qt 4.3 引入。
另请参阅 setControlType ().
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.
另请参阅 horizontalPolicy () 和 verticalPolicy ().
Returns true if the widget's preferred height depends on its width; otherwise returns false.
另请参阅 setHeightForWidth ().
Returns true if the widget's width depends on its height; otherwise returns false.
该函数在 Qt 4.8 引入。
另请参阅 setWidthForHeight ().
Returns the horizontal component of the size policy.
另请参阅 setHorizontalPolicy (), verticalPolicy (),和 horizontalStretch ().
Returns the horizontal stretch factor of the size policy.
另请参阅 setHorizontalStretch (), verticalStretch (), and horizontalPolicy ().
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.
该函数在 Qt 4.3 引入。
另请参阅 controlType () 和 QStyle.layoutSpacing ().
Sets the flag determining whether the widget's preferred height depends on its width, to dependent .
另请参阅 hasHeightForWidth () 和 setWidthForHeight ().
Sets the horizontal component to the given policy .
另请参阅 horizontalPolicy (), setVerticalPolicy (), and setHorizontalStretch ().
Sets the horizontal stretch factor of the size policy to the given stretchFactor .
另请参阅 horizontalStretch (), setVerticalStretch (),和 setHorizontalPolicy ().
Sets the vertical component to the given policy .
另请参阅 verticalPolicy (), setHorizontalPolicy (), and setVerticalStretch ().
Sets the vertical stretch factor of the size policy to the given stretchFactor .
另请参阅 verticalStretch (), setHorizontalStretch (), and setVerticalPolicy ().
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.
该函数在 Qt 4.8 引入。
另请参阅 hasWidthForHeight () 和 setHeightForWidth ().
Swaps the horizontal and vertical policies and stretches.
返回尺寸策略的垂直组件。
另请参阅 setVerticalPolicy (), horizontalPolicy (), and verticalStretch ().
返回尺寸策略的垂直拉伸因子。
另请参阅 setVerticalStretch (), horizontalStretch (),和 verticalPolicy ().