QSizePolicy Class
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy. More…
| Header | #include <QSizePolicy> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
List of all members, including inherited members
Public Types
| enum | PolicyFlag |
| enum | Policy |
Public Functions
| QSizePolicy() | |
| QSizePolicy(Policy horizontal, Policy vertical) | |
| Policy | horizontalPolicy() const |
| Policy | verticalPolicy() const |
| void | setHorizontalPolicy(Policy policy) |
| void | setVerticalPolicy(Policy policy) |
| int | horizontalStretch() const |
| int | verticalStretch() const |
| void | setHorizontalStretch(int stretch) |
| void | setVerticalStretch(int stretch) |
| Qt::Orientations | expandingDirections() const |
Detailed Description
A widget's size policy tells layouts how it may be resized. Each direction has a policy: whether the widget can grow beyond its size hint, shrink below it, and whether it wants to take extra space.
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
See also QWidget::setSizePolicy() and QLayout.
Differences from Qt
There is no height-for-width support, retainSizeWhenHidden(), ControlType or transposed(). The policy is a plain value with the stretch factors, which the box layouts of Nt do not use: use QBoxLayout::addWidget()'s stretch argument.
Member Type Documentation
enum QSizePolicy::Policy
This enum describes how a widget can be resized in one direction.
| Constant | Description |
|---|---|
QSizePolicy::Fixed | The size hint is the only size that the widget can have. |
QSizePolicy::Minimum | The size hint is the smallest size; the widget can grow. |
QSizePolicy::Maximum | The size hint is the largest size; the widget can shrink. |
QSizePolicy::Preferred | The size hint is best, but the widget can grow and shrink. |
QSizePolicy::MinimumExpanding | The size hint is the smallest size; the widget can grow and wants to. |
QSizePolicy::Expanding | The size hint is a sensible size; the widget can grow and shrink and wants to grow. |
QSizePolicy::Ignored | The size hint is ignored; the widget gets as much space as it can. |
enum QSizePolicy::PolicyFlag
These flags make up the policies. A policy is a combination of them.
| Constant | Description |
|---|---|
QSizePolicy::GrowFlag | The widget can grow beyond its size hint if necessary. |
QSizePolicy::ExpandFlag | The widget wants to get as much space as possible. |
QSizePolicy::ShrinkFlag | The widget can shrink below its size hint if necessary. |
QSizePolicy::IgnoreFlag | The size hint is ignored; the widget gets as much space as it can. |
Member Function Documentation
QSizePolicy::QSizePolicy()
Constructs a policy that is Preferred in both directions.
QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical)
This is an overloaded function.
Constructs a policy with the given horizontal and vertical policies.
Qt::Orientations QSizePolicy::expandingDirections() const
Returns the directions in which the widget wants to expand: those whose policy has the ExpandFlag.
Policy QSizePolicy::horizontalPolicy() const
Returns the horizontal policy.
See also setHorizontalPolicy().
int QSizePolicy::horizontalStretch() const
Returns the horizontal stretch factor.
See also setHorizontalStretch().
void QSizePolicy::setHorizontalPolicy(Policy policy)
Sets the horizontal policy to policy.
See also horizontalPolicy().
void QSizePolicy::setHorizontalStretch(int stretch)
Sets the horizontal stretch factor to stretch.
See also horizontalStretch().
void QSizePolicy::setVerticalPolicy(Policy policy)
Sets the vertical policy to policy.
See also verticalPolicy().
void QSizePolicy::setVerticalStretch(int stretch)
Sets the vertical stretch factor to stretch.
See also verticalStretch().
Policy QSizePolicy::verticalPolicy() const
Returns the vertical policy.
See also setVerticalPolicy().
int QSizePolicy::verticalStretch() const
Returns the vertical stretch factor.
See also setVerticalStretch().