QLayout Class

The QLayout class is the base class of geometry managers. More...

Header: #include <QLayout>
qmake: QT += widgets
Inherits: QObject and QLayoutItem
Inherited By:

QBoxLayout, QFormLayout, QGridLayout, and QStackedLayout

Public Types

enum SizeConstraint { SetDefaultConstraint, SetFixedSize, SetMinimumSize, SetMaximumSize, SetMinAndMaxSize, SetNoConstraint }

Properties

Public Functions

void setSizeConstraint(QLayout::SizeConstraint)
void setSpacing(int)
QLayout::SizeConstraint sizeConstraint() const
int spacing() const

Detailed Description

This is an abstract base class inherited by the concrete classes QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout.

For users of QLayout subclasses or of QMainWindow there is seldom any need to use the basic functions provided by QLayout, such as setSizeConstraint() or setMenuBar(). See Layout Management for more information.

To make your own layout manager, implement the functions addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You should also implement minimumSize() to ensure your layout isn't resized to zero size if there is too little space. To support children whose heights depend on their widths, implement hasHeightForWidth() and heightForWidth(). See the Border Layout and Flow Layout examples for more information about implementing custom layout managers.

Geometry management stops when the layout manager is deleted.

See also QLayoutItem, Layout Management, Basic Layouts Example, Border Layout Example, and Flow Layout Example.

Member Type Documentation

enum QLayout::SizeConstraint

The possible values are:

ConstantValueDescription
QLayout::SetDefaultConstraint0The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize3The main widget's size is set to sizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize2The main widget's minimum size is set to minimumSize(); it cannot be smaller.
QLayout::SetMaximumSize4The main widget's maximum size is set to maximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize5The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize().
QLayout::SetNoConstraint1The widget is not constrained.

See also setSizeConstraint().

Property Documentation

sizeConstraint : SizeConstraint

This property holds the resize mode of the layout

The default mode is SetDefaultConstraint.

Access functions:

QLayout::SizeConstraint sizeConstraint() const
void setSizeConstraint(QLayout::SizeConstraint)

spacing : int

This property holds the spacing between widgets inside the layout

If no value is explicitly set, the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.

For QGridLayout and QFormLayout, it is possible to set different horizontal and vertical spacings using setHorizontalSpacing() and setVerticalSpacing(). In that case, spacing() returns -1.

Access functions:

int spacing() const
void setSpacing(int)

See also contentsRect(), getContentsMargins(), QStyle::layoutSpacing(), and QStyle::pixelMetric().