QSizePolicyclass is a layout attribute describing horizontal and vertical resizing policy. 更多 …
def
__eq__
(s)
def
__ne__
(s)
def
controlType
()
def
expandingDirections
()
def
hasHeightForWidth
()
def
hasWidthForHeight
()
def
horizontalPolicy
()
def
horizontalStretch
()
def
retainSizeWhenHidden
()
def
setControlType
(type)
def
setHeightForWidth
(b)
def
setHorizontalPolicy
(d)
def
setHorizontalStretch
(stretchFactor)
def
setRetainSizeWhenHidden
(retainSize)
def
setVerticalPolicy
(d)
def
setVerticalStretch
(stretchFactor)
def
setWidthForHeight
(b)
def
transpose
()
def
transposed
()
def
verticalPolicy
()
def
verticalStretch
()
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 itssizePolicy特性。
QSizePolicycontains two independentPolicyvalues 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()andsetVerticalPolicy()functions. The stretch factors can be set using thesetHorizontalStretch()andsetVerticalStretch()functions. The flag indicating whether the widget’ssizeHint()is width-dependent (such as a menu bar or a word-wrapping label) can be set using thesetHeightForWidth()函数。The current size policies and stretch factors be retrieved using the
horizontalPolicy(),verticalPolicy(),horizontalStretch()andverticalStretch()functions. Alternatively, use thetranspose()function to swap the horizontal and vertical policies and stretches. ThehasHeightForWidth()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 itssizeHint()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 aQVariantoperator storing thisQSizePolicy作为QVariant对象。
QSizePolicy
¶
QSizePolicy(horizontal, vertical[, type=DefaultType])
- param type
ControlType- param vertical
Policy- param horizontal
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).
构造
QSizePolicy
对象采用给定
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).
PySide2.QtWidgets.QSizePolicy.
PolicyFlag
¶
These flags are combined together to form the various
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. |
另请参阅
Policy
PySide2.QtWidgets.QSizePolicy.
Policy
¶
This enum describes the various per-dimension sizing types used when constructing a
QSizePolicy
.
|
常量 |
描述 |
|---|---|
|
QSizePolicy.Fixed |
|
|
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
|
|
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. |
另请参阅
PolicyFlag
setHorizontalPolicy()
setVerticalPolicy()
PySide2.QtWidgets.QSizePolicy.
ControlType
¶
此枚举指定 Widget 的不同类型,就布局交互而言:
|
常量 |
描述 |
|---|---|
|
QSizePolicy.DefaultType |
The default type, when none is specified. |
|
QSizePolicy.ButtonBox |
A
|
|
QSizePolicy.CheckBox |
A
|
|
QSizePolicy.ComboBox |
A
|
|
QSizePolicy.Frame |
A
|
|
QSizePolicy.GroupBox |
A
|
|
QSizePolicy.Label |
A
|
|
QSizePolicy.Line |
A
|
|
QSizePolicy.LineEdit |
A
|
|
QSizePolicy.PushButton |
A
|
|
QSizePolicy.RadioButton |
A
|
|
QSizePolicy.Slider |
A
|
|
QSizePolicy.SpinBox |
A
|
|
QSizePolicy.TabWidget |
A
|
|
QSizePolicy.ToolButton |
A
|
PySide2.QtWidgets.QSizePolicy.
controlType
(
)
¶
Returns the control type associated with the widget for which this size policy applies.
另请参阅
PySide2.QtWidgets.QSizePolicy.
expandingDirections
(
)
¶
Orientations
Returns whether a widget can make use of more space than the
sizeHint()
function indicates.
A value of
Horizontal
or
Vertical
means that the widget can grow horizontally or vertically (i.e., the horizontal or vertical policy is
Expanding
or
MinimumExpanding
), whereas
Horizontal
|
Vertical
means that it can grow in both dimensions.
PySide2.QtWidgets.QSizePolicy.
hasHeightForWidth
(
)
¶
bool
返回
true
if the widget’s preferred height depends on its width; otherwise returns
false
.
另请参阅
PySide2.QtWidgets.QSizePolicy.
hasWidthForHeight
(
)
¶
bool
返回
true
if the widget’s width depends on its height; otherwise returns
false
.
另请参阅
PySide2.QtWidgets.QSizePolicy.
horizontalPolicy
(
)
¶
Returns the horizontal component of the size policy.
PySide2.QtWidgets.QSizePolicy.
horizontalStretch
(
)
¶
int
Returns the horizontal stretch factor of the size policy.
PySide2.QtWidgets.QSizePolicy.
__ne__
(
s
)
¶
s
–
QSizePolicy
bool
返回
true
若此策略不同于
other
;否则返回
false
.
另请参阅
operator==()
PySide2.QtWidgets.QSizePolicy.
__eq__
(
s
)
¶
s
–
QSizePolicy
bool
返回
true
若此策略等于
other
;否则返回
false
.
另请参阅
operator!=()
PySide2.QtWidgets.QSizePolicy.
retainSizeWhenHidden
(
)
¶
bool
Returns whether the layout should retain the widget’s size when it is hidden. This is
false
在默认情况下。
PySide2.QtWidgets.QSizePolicy.
setControlType
(
type
)
¶
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.
PySide2.QtWidgets.QSizePolicy.
setHeightForWidth
(
b
)
¶
b
–
bool
Sets the flag determining whether the widget’s preferred height depends on its width, to
dependent
.
PySide2.QtWidgets.QSizePolicy.
setHorizontalPolicy
(
d
)
¶
d
–
Policy
Sets the horizontal component to the given
policy
.
PySide2.QtWidgets.QSizePolicy.
setHorizontalStretch
(
stretchFactor
)
¶
stretchFactor
–
int
Sets the horizontal stretch factor of the size policy to the given
stretchFactor
.
stretchFactor
must 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.
PySide2.QtWidgets.QSizePolicy.
setRetainSizeWhenHidden
(
retainSize
)
¶
retainSize
–
bool
Sets whether a layout should retain the widget’s size when it is hidden. If
retainSize
is
true
, the layout will not be changed by hiding the widget.
PySide2.QtWidgets.QSizePolicy.
setVerticalPolicy
(
d
)
¶
d
–
Policy
Sets the vertical component to the given
policy
.
PySide2.QtWidgets.QSizePolicy.
setVerticalStretch
(
stretchFactor
)
¶
stretchFactor
–
int
Sets the vertical stretch factor of the size policy to the given
stretchFactor
.
stretchFactor
must 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.
PySide2.QtWidgets.QSizePolicy.
setWidthForHeight
(
b
)
¶
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.
PySide2.QtWidgets.QSizePolicy.
transpose
(
)
¶
Swaps the horizontal and vertical policies and stretches.
另请参阅
PySide2.QtWidgets.QSizePolicy.
transposed
(
)
¶
Returns a size policy object with the horizontal and vertical policies and stretches swapped.
另请参阅
PySide2.QtWidgets.QSizePolicy.
verticalStretch
(
)
¶
int
返回尺寸策略的垂直拉伸因子。