6.0.0-rc4Source

QSizePolicy Class

The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy. More…

Header#include <QSizePolicy>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes

List of all members, including inherited members

Public Types

enumPolicyFlag
enumPolicy

Public Functions

QSizePolicy()
QSizePolicy(Policy horizontal, Policy vertical)
PolicyhorizontalPolicy() const
PolicyverticalPolicy() const
voidsetHorizontalPolicy(Policy policy)
voidsetVerticalPolicy(Policy policy)
inthorizontalStretch() const
intverticalStretch() const
voidsetHorizontalStretch(int stretch)
voidsetVerticalStretch(int stretch)
Qt::OrientationsexpandingDirections() 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.

ConstantDescription
QSizePolicy::FixedThe size hint is the only size that the widget can have.
QSizePolicy::MinimumThe size hint is the smallest size; the widget can grow.
QSizePolicy::MaximumThe size hint is the largest size; the widget can shrink.
QSizePolicy::PreferredThe size hint is best, but the widget can grow and shrink.
QSizePolicy::MinimumExpandingThe size hint is the smallest size; the widget can grow and wants to.
QSizePolicy::ExpandingThe size hint is a sensible size; the widget can grow and shrink and wants to grow.
QSizePolicy::IgnoredThe 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.

ConstantDescription
QSizePolicy::GrowFlagThe widget can grow beyond its size hint if necessary.
QSizePolicy::ExpandFlagThe widget wants to get as much space as possible.
QSizePolicy::ShrinkFlagThe widget can shrink below its size hint if necessary.
QSizePolicy::IgnoreFlagThe size hint is ignored; the widget gets as much space as it can.

Member Function Documentation

[constexpr] QSizePolicy::QSizePolicy()

Constructs a policy that is Preferred in both directions.

[constexpr] QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical)

This is an overloaded function.

Constructs a policy with the given horizontal and vertical policies.

[constexpr] Qt::Orientations QSizePolicy::expandingDirections() const

Returns the directions in which the widget wants to expand: those whose policy has the ExpandFlag.

[constexpr] Policy QSizePolicy::horizontalPolicy() const

Returns the horizontal policy.

See also setHorizontalPolicy().

[constexpr] int QSizePolicy::horizontalStretch() const

Returns the horizontal stretch factor.

See also setHorizontalStretch().

[constexpr] void QSizePolicy::setHorizontalPolicy(Policy policy)

Sets the horizontal policy to policy.

See also horizontalPolicy().

[constexpr] void QSizePolicy::setHorizontalStretch(int stretch)

Sets the horizontal stretch factor to stretch.

See also horizontalStretch().

[constexpr] void QSizePolicy::setVerticalPolicy(Policy policy)

Sets the vertical policy to policy.

See also verticalPolicy().

[constexpr] void QSizePolicy::setVerticalStretch(int stretch)

Sets the vertical stretch factor to stretch.

See also verticalStretch().

[constexpr] Policy QSizePolicy::verticalPolicy() const

Returns the vertical policy.

See also setVerticalPolicy().

[constexpr] int QSizePolicy::verticalStretch() const

Returns the vertical stretch factor.

See also setVerticalStretch().