QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | Friends | List of all members
QLayout Class Referenceabstract

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

#include <qlayout.h>

Inheritance diagram for QLayout:
Inheritance graph
[legend]
Collaboration diagram for QLayout:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 QLayout (QWidget *parent=nullptr)
 
 ~QLayout ()
 
virtual int spacing () const
 
virtual void setSpacing (int)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContentsMargins (const QMargins &margins)
 
void unsetContentsMargins ()
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
bool setAlignment (QWidget *w, Qt::Alignment alignment)
 
bool setAlignment (QLayout *l, Qt::Alignment alignment)
 
void setSizeConstraint (SizeConstraint)
 
SizeConstraint sizeConstraint () const
 
void setMenuBar (QWidget *w)
 
QWidgetmenuBar () const
 
QWidgetparentWidget () const
 
void invalidate () override
 
QRect geometry () const override
 
bool activate ()
 
void update ()
 
void addWidget (QWidget *w)
 
virtual void addItem (QLayoutItem *)=0
 
void removeWidget (QWidget *w)
 
void removeItem (QLayoutItem *)
 
Qt::Orientations expandingDirections () const override
 
QSize minimumSize () const override
 
QSize maximumSize () const override
 
virtual void setGeometry (const QRect &) override
 
virtual QLayoutItemitemAt (int index) const =0
 
virtual QLayoutItemtakeAt (int index)=0
 
virtual int indexOf (const QWidget *) const
 
virtual int indexOf (const QLayoutItem *) const
 
virtual int count () const =0
 
bool isEmpty () const override
 
QSizePolicy::ControlTypes controlTypes () const override
 
virtual QLayoutItemreplaceWidget (QWidget *from, QWidget *to, Qt::FindChildOptions options=Qt::FindChildrenRecursively)
 
int totalMinimumHeightForWidth (int w) const
 
int totalHeightForWidth (int w) const
 
QSize totalMinimumSize () const
 
QSize totalMaximumSize () const
 
QSize totalSizeHint () const
 
QLayoutlayout () override
 
void setEnabled (bool)
 
bool isEnabled () const
 
void setAlignment (Qt::Alignment a)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 
- Public Member Functions inherited from QLayoutItem
 QLayoutItem (Qt::Alignment alignment=Qt::Alignment())
 
virtual ~QLayoutItem ()
 
virtual QSize sizeHint () const =0
 
virtual bool hasHeightForWidth () const
 
virtual int heightForWidth (int) const
 
virtual int minimumHeightForWidth (int) const
 
virtual QWidgetwidget () const
 
virtual QSpacerItemspacerItem ()
 
Qt::Alignment alignment () const
 
void setAlignment (Qt::Alignment a)
 

Static Public Member Functions

static QSize closestAcceptableSize (const QWidget *w, const QSize &s)
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 

Protected Member Functions

void widgetEvent (QEvent *)
 
void childEvent (QChildEvent *e) override
 
void addChildLayout (QLayout *l)
 
void addChildWidget (QWidget *w)
 
bool adoptLayout (QLayout *layout)
 
QRect alignmentRect (const QRect &) const
 
 QLayout (QLayoutPrivate &d, QLayout *, QWidget *)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

int spacing
 the spacing between widgets inside the layout More...
 
QMargins contentsMargins
 
SizeConstraint sizeConstraint
 the resize mode of the layout More...
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Friends

class QApplicationPrivate
 
class QWidget
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QLayoutItem
Qt::Alignment align
 

Detailed Description

The QLayout class is the base class of geometry managers.

\inmodule QtWidgets

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 \l{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 \l{layouts/borderlayout}{Border Layout} and \l{layouts/flowlayout}{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}, {Flow Layout Example}

Definition at line 61 of file qlayout.h.

Member Enumeration Documentation

◆ SizeConstraint

The possible values are:

\value SetDefaultConstraint The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size.

\value SetFixedSize The main widget's size is set to sizeHint(); it cannot be resized at all. \value SetMinimumSize The main widget's minimum size is set to minimumSize(); it cannot be smaller.

\value SetMaximumSize The main widget's maximum size is set to maximumSize(); it cannot be larger.

\value SetMinAndMaxSize The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize().

\value SetNoConstraint The widget is not constrained.

See also
setSizeConstraint()
Enumerator
SetDefaultConstraint 
SetNoConstraint 
SetMinimumSize 
SetFixedSize 
SetMaximumSize 
SetMinAndMaxSize 

Definition at line 71 of file qlayout.h.

Constructor & Destructor Documentation

◆ QLayout() [1/2]

QLayout::QLayout ( QWidget parent = nullptr)
explicit

Constructs a new top-level QLayout, with parent parent.

The layout is set directly as the top-level layout for parent. There can be only one top-level layout for a widget. It is returned by QWidget::layout().

If parent is \nullptr, then you must insert this layout into another layout, or set it as a widget's layout using QWidget::setLayout().

See also
QWidget::setLayout()

Definition at line 120 of file qlayout.cpp.

◆ ~QLayout()

QLayout::~QLayout ( )

Definition at line 734 of file qlayout.cpp.

Here is the call graph for this function:

◆ QLayout() [2/2]

QLayout::QLayout ( QLayoutPrivate d,
QLayout lay,
QWidget w 
)
protected

Definition at line 130 of file qlayout.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ activate()

bool QLayout::activate ( )

Redoes the layout for parentWidget() if necessary.

You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.

See also
update(), QWidget::updateGeometry()

Definition at line 1028 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addChildLayout()

void QLayout::addChildLayout ( QLayout l)
protected

This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as a sub-layout.

The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.

See also
QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout()

Definition at line 753 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addChildWidget()

void QLayout::addChildWidget ( QWidget w)
protected

This function is called from addWidget() functions in subclasses to add w as a managed widget of a layout.

If w is already managed by a layout, this function will give a warning and remove w from that layout. This function must therefore be called before adding w to the layout's data structure.

Definition at line 870 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addItem()

void QLayout::addItem ( QLayoutItem item)
pure virtual

Implemented in subclasses to add an item. How it is added is specific to each subclass.

This function is not usually called in application code. To add a widget to a layout, use the addWidget() function; to add a child layout, use the addLayout() function provided by the relevant QLayout subclass.

{Note:} The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.

See also
addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout()

Implemented in QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QStackedLayout, QFormLayout, CardLayout, FlowLayout, BorderLayout, MyLayout, QGridLayout, and QBoxLayout.

Here is the caller graph for this function:

◆ addWidget()

void QLayout::addWidget ( QWidget w)

Adds widget w to this layout in a manner specific to the layout. This function uses addItem().

Definition at line 223 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adoptLayout()

bool QLayout::adoptLayout ( QLayout layout)
protected

Definition at line 771 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ alignmentRect()

QRect QLayout::alignmentRect ( const QRect r) const
protected

Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment().

The result is derived from sizeHint() and expanding(). It is never larger than r.

Definition at line 1298 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ childEvent()

void QLayout::childEvent ( QChildEvent e)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Definition at line 594 of file qlayout.cpp.

Here is the call graph for this function:

◆ closestAcceptableSize()

QSize QLayout::closestAcceptableSize ( const QWidget widget,
const QSize size 
)
static

Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.

Definition at line 1431 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contentsMargins()

QMargins QLayout::contentsMargins ( ) const
Since
4.6

Returns the margins used around the layout.

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
setContentsMargins()

Definition at line 403 of file qlayout.cpp.

Here is the call graph for this function:

◆ contentsRect()

QRect QLayout::contentsRect ( ) const
Since
4.3

Returns the layout's geometry() rectangle, but taking into account the contents margins.

See also
setContentsMargins(), getContentsMargins()

Definition at line 418 of file qlayout.cpp.

Here is the call graph for this function:

◆ controlTypes()

QSizePolicy::ControlTypes QLayout::controlTypes ( ) const
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 475 of file qlayout.cpp.

Here is the call graph for this function:

◆ count()

int * QLayout::count ( ) const
pure virtual

Must be implemented in subclasses to return the number of items in the layout.

See also
itemAt()

Implemented in MyLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QStackedLayout, QGridLayout, QFormLayout, QBoxLayout, CardLayout, FlowLayout, BorderLayout, and FlowLayout.

Here is the caller graph for this function:

◆ expandingDirections()

Qt::Orientations QLayout::expandingDirections ( ) const
overridevirtual

Returns whether this layout can make use of more space than sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only one dimension, whereas Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions.

The default implementation returns Qt::Horizontal | Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets's \l{QSizePolicy}{size policies}.

See also
sizeHint()

Implements QLayoutItem.

Reimplemented in QToolBarLayout.

Definition at line 977 of file qlayout.cpp.

Here is the caller graph for this function:

◆ geometry()

QRect QLayout::geometry ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Definition at line 497 of file qlayout.cpp.

Here is the caller graph for this function:

◆ getContentsMargins()

void QLayout::getContentsMargins ( int *  left,
int *  top,
int *  right,
int *  bottom 
) const
Since
4.3

For each of left, top, right and bottom that is not \nullptr, stores the size of the margin named in the location the pointer refers to.

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
setContentsMargins(), QStyle::pixelMetric(), {QStyle::}{PM_LayoutLeftMargin}, {QStyle::}{PM_LayoutTopMargin}, {QStyle::}{PM_LayoutRightMargin}, {QStyle::}{PM_LayoutBottomMargin}

Definition at line 384 of file qlayout.cpp.

Here is the caller graph for this function:

◆ indexOf() [1/2]

int QLayout::indexOf ( const QLayoutItem layoutItem) const
virtual
Since
5.12 Searches for layout item layoutItem in this layout (not including child layouts).

Returns the index of layoutItem, or -1 if layoutItem is not found.

Definition at line 1229 of file qlayout.cpp.

Here is the call graph for this function:

◆ indexOf() [2/2]

int QLayout::indexOf ( const QWidget widget) const
virtual

Searches for widget widget in this layout (not including child layouts).

Returns the index of widget, or -1 if widget is not found.

The default implementation iterates over all items using itemAt().

Definition at line 1210 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalidate()

void QLayout::invalidate ( )
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Reimplemented in MyLayout, QToolBarLayout, and QMainWindowLayout.

Definition at line 506 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpty()

bool QLayout::isEmpty ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Reimplemented in QToolBarLayout.

Definition at line 459 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEnabled()

bool QLayout::isEnabled ( ) const

Returns true if the layout is enabled; otherwise returns false.

See also
setEnabled()

Definition at line 1419 of file qlayout.cpp.

◆ itemAt()

QLayoutItem * QLayout::itemAt ( int  index) const
pure virtual

Must be implemented in subclasses to return the layout item at index. If there is no such item, the function must return \nullptr. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

See also
count(), takeAt()

Implemented in MyLayout, QStackedLayout, QBoxLayout, CardLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, QFormLayout, FlowLayout, BorderLayout, and FlowLayout.

Here is the caller graph for this function:

◆ layout()

QLayout * QLayout::layout ( )
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 333 of file qlayoutitem.cpp.

Here is the caller graph for this function:

◆ maximumSize()

QSize QLayout::maximumSize ( ) const
overridevirtual

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Implements QLayoutItem.

Reimplemented in QDockWidgetLayout.

Definition at line 960 of file qlayout.cpp.

Here is the caller graph for this function:

◆ menuBar()

QWidget * QLayout::menuBar ( ) const

Returns the menu bar set for this layout, or \nullptr if no menu bar is set.

Definition at line 928 of file qlayout.cpp.

◆ minimumSize()

QSize QLayout::minimumSize ( ) const
overridevirtual

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Implements QLayoutItem.

Reimplemented in QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, and QStackedLayout.

Definition at line 945 of file qlayout.cpp.

Here is the caller graph for this function:

◆ parentWidget()

QWidget * QLayout::parentWidget ( ) const

Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget.

If the layout is a sub-layout, this function returns the parent widget of the parent layout.

See also
parent()

Definition at line 436 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeItem()

void QLayout::removeItem ( QLayoutItem item)

Removes the layout item item from the layout. It is the caller's responsibility to delete the item.

Notice that item can be a layout (since QLayout inherits QLayoutItem).

See also
removeWidget(), addItem()

Definition at line 1384 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeWidget()

void QLayout::removeWidget ( QWidget widget)

Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout or to explicitly hide it if necessary.

{Note:} The ownership of widget remains the same as when it was added.

See also
removeItem(), QWidget::setGeometry(), addWidget()

Definition at line 1356 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replaceWidget()

QLayoutItem * QLayout::replaceWidget ( QWidget from,
QWidget to,
Qt::FindChildOptions  options = Qt::FindChildrenRecursively 
)
virtual
Since
5.2

Searches for widget from and replaces it with widget to if found. Returns the layout item that contains the widget from on success. Otherwise \nullptr is returned. If options contains Qt::FindChildrenRecursively (the default), sub-layouts are searched for doing the replacement. Any other flag in options is ignored.

Notice that the returned item therefore might not belong to this layout, but to a sub-layout.

The returned layout item is no longer owned by the layout and should be either deleted or inserted to another layout. The widget from is no longer managed by the layout and may need to be deleted or hidden. The parent of widget from is left unchanged.

This function works for the built-in Qt layouts, but might not work for custom layouts.

See also
indexOf()

Definition at line 1123 of file qlayout.cpp.

◆ setAlignment() [1/3]

bool QLayout::setAlignment ( QLayout l,
Qt::Alignment  alignment 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the alignment for the layout l to alignment and returns true if l is found in this layout (not including child layouts); otherwise returns false.

Definition at line 259 of file qlayout.cpp.

Here is the call graph for this function:

◆ setAlignment() [2/3]

void QLayoutItem::setAlignment

Sets the alignment of this item to alignment.

{Note:} Item alignment is only supported by QLayoutItem subclasses where it would have a visual effect. Except for QSpacerItem, which provides blank space for layouts, all public Qt classes that inherit QLayoutItem support item alignment.

Definition at line 82 of file qlayoutitem.cpp.

◆ setAlignment() [3/3]

bool QLayout::setAlignment ( QWidget w,
Qt::Alignment  alignment 
)

Sets the alignment for widget w to alignment and returns true if w is found in this layout (not including child layouts); otherwise returns false.

Definition at line 236 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setContentsMargins() [1/2]

void QLayout::setContentsMargins ( const QMargins margins)
Since
4.6

Sets the margins to use around the layout.

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
contentsMargins()

Definition at line 350 of file qlayout.cpp.

Here is the call graph for this function:

◆ setContentsMargins() [2/2]

void QLayout::setContentsMargins ( int  left,
int  top,
int  right,
int  bottom 
)
Since
4.3

Sets the left, top, right, and bottom margins to use around the layout.

By default, QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

See also
getContentsMargins(), QStyle::pixelMetric(), {QStyle::}{PM_LayoutLeftMargin}, {QStyle::}{PM_LayoutTopMargin}, {QStyle::}{PM_LayoutRightMargin}, {QStyle::}{PM_LayoutBottomMargin}

Definition at line 325 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEnabled()

void QLayout::setEnabled ( bool  enable)

Enables this layout if enable is true, otherwise disables it.

An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

By default all layouts are enabled.

See also
isEnabled()

Definition at line 1408 of file qlayout.cpp.

◆ setGeometry()

void QLayout::setGeometry ( const QRect r)
overridevirtual

\reimp

Implements QLayoutItem.

Reimplemented in QStackedLayout, QFormLayout, CardLayout, FlowLayout, BorderLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, and QBoxLayout.

Definition at line 488 of file qlayout.cpp.

Here is the caller graph for this function:

◆ setMenuBar()

void QLayout::setMenuBar ( QWidget widget)

Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). All child widgets are placed below the bottom edge of the menu bar.

Definition at line 915 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSizeConstraint()

void QLayout::setSizeConstraint ( SizeConstraint  constraint)

Definition at line 1274 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSpacing()

void QLayout::setSpacing ( int  spacing)
virtual

Reimplemented in QFormLayout, QGridLayout, and QBoxLayout.

Definition at line 303 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sizeConstraint()

QLayout::SizeConstraint QLayout::sizeConstraint ( ) const

Definition at line 1284 of file qlayout.cpp.

◆ spacing()

int QLayout::spacing ( ) const
virtual

Reimplemented in QGridLayout, QFormLayout, and QBoxLayout.

Definition at line 292 of file qlayout.cpp.

Here is the call graph for this function:

◆ takeAt()

QLayoutItem * QLayout::takeAt ( int  index)
pure virtual

Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.

The following code fragment shows a safe way to remove all items from a layout:

See also
itemAt(), count()

Implemented in MyLayout, QStackedLayout, QBoxLayout, CardLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, QFormLayout, FlowLayout, and BorderLayout.

Here is the caller graph for this function:

◆ totalHeightForWidth()

int QLayout::totalHeightForWidth ( int  w) const

Definition at line 633 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ totalMaximumSize()

QSize QLayout::totalMaximumSize ( ) const

Definition at line 703 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ totalMinimumHeightForWidth()

int QLayout::totalMinimumHeightForWidth ( int  w) const

Definition at line 611 of file qlayout.cpp.

Here is the call graph for this function:

◆ totalMinimumSize()

QSize QLayout::totalMinimumSize ( ) const

Definition at line 655 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ totalSizeHint()

QSize QLayout::totalSizeHint ( ) const

Definition at line 678 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsetContentsMargins()

void QLayout::unsetContentsMargins ( )
Since
6.1

Unsets any user-defined margins around the layout. The layout will use the default values provided by the style.

See also
setContentsMargins()

Definition at line 363 of file qlayout.cpp.

Here is the call graph for this function:

◆ update()

void QLayout::update ( )

Updates the layout for parentWidget().

You should generally not need to call this because it is automatically called at the most appropriate times.

See also
activate(), invalidate()

Definition at line 1004 of file qlayout.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ widgetEvent()

void QLayout::widgetEvent ( QEvent e)
protected

Definition at line 557 of file qlayout.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 160 of file qlayout.h.

◆ QWidget

friend class QWidget
friend

Definition at line 161 of file qlayout.h.

Property Documentation

◆ contentsMargins

QMargins QLayout::contentsMargins
readwrite

Definition at line 165 of file qlayout.h.

◆ sizeConstraint

QLayout::sizeConstraint
readwrite

the resize mode of the layout

The default mode is \l {QLayout::SetDefaultConstraint} {SetDefaultConstraint}.

Definition at line 165 of file qlayout.h.

◆ spacing

QLayout::spacing
readwrite

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 \l{QGridLayout::}{setHorizontalSpacing()} and \l{QGridLayout::}{setVerticalSpacing()}. In that case, spacing() returns -1.

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

Definition at line 165 of file qlayout.h.


The documentation for this class was generated from the following files: