![]() |
Qt 6.x
The Qt SDK
|
The QLayout class is the base class of geometry managers. More...
#include <qlayout.h>
Public Types | |
enum | SizeConstraint { SetDefaultConstraint , SetNoConstraint , SetMinimumSize , SetFixedSize , SetMaximumSize , SetMinAndMaxSize } |
The possible values are: More... | |
Public Member Functions | |
QLayout (QWidget *parent=nullptr) | |
Constructs a new top-level QLayout, with parent parent. | |
~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) |
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 . | |
bool | 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 . | |
void | setSizeConstraint (SizeConstraint) |
SizeConstraint | sizeConstraint () const |
void | setMenuBar (QWidget *w) |
Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). | |
QWidget * | menuBar () const |
Returns the menu bar set for this layout, or \nullptr if no menu bar is set. | |
QWidget * | parentWidget () const |
Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget. | |
void | invalidate () override |
\reimp | |
QRect | geometry () const override |
\reimp | |
bool | activate () |
Redoes the layout for parentWidget() if necessary. | |
void | update () |
Updates the layout for parentWidget(). | |
void | addWidget (QWidget *w) |
Adds widget w to this layout in a manner specific to the layout. | |
virtual void | addItem (QLayoutItem *)=0 |
Implemented in subclasses to add an item. | |
void | removeWidget (QWidget *w) |
Removes the widget widget from the layout. | |
void | removeItem (QLayoutItem *) |
Removes the layout item item from the layout. | |
Qt::Orientations | expandingDirections () const override |
Returns whether this layout can make use of more space than sizeHint(). | |
QSize | minimumSize () const override |
Returns the minimum size of this layout. | |
QSize | maximumSize () const override |
Returns the maximum size of this layout. | |
virtual void | setGeometry (const QRect &) override |
\reimp | |
virtual QLayoutItem * | itemAt (int index) const =0 |
Must be implemented in subclasses to return the layout item at index. | |
virtual QLayoutItem * | takeAt (int index)=0 |
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. | |
virtual int | indexOf (const QWidget *) const |
Searches for widget widget in this layout (not including child layouts). | |
virtual int | indexOf (const QLayoutItem *) const |
virtual int | count () const =0 |
Must be implemented in subclasses to return the number of items in the layout. | |
bool | isEmpty () const override |
\reimp | |
QSizePolicy::ControlTypes | controlTypes () const override |
\reimp | |
virtual QLayoutItem * | replaceWidget (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 |
QLayout * | layout () override |
\reimp | |
void | setEnabled (bool) |
Enables this layout if enable is true, otherwise disables it. | |
bool | isEnabled () const |
Returns true if the layout is enabled; otherwise returns false . | |
void | setAlignment (Qt::Alignment a) |
Sets the alignment of this item to alignment. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
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 |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
![]() | |
QLayoutItem (Qt::Alignment alignment=Qt::Alignment()) | |
Constructs a layout item with an alignment. | |
virtual | ~QLayoutItem () |
Destroys the QLayoutItem. | |
virtual QSize | sizeHint () const =0 |
Implemented in subclasses to return the preferred size of this item. | |
virtual QSize | minimumSize () const =0 |
Implemented in subclasses to return the minimum size of this item. | |
virtual QSize | maximumSize () const =0 |
Implemented in subclasses to return the maximum size of this item. | |
virtual Qt::Orientations | expandingDirections () const =0 |
Returns whether this layout item can make use of more space than sizeHint(). | |
virtual void | setGeometry (const QRect &)=0 |
Implemented in subclasses to set this item's geometry to r. | |
virtual QRect | geometry () const =0 |
Returns the rectangle covered by this layout item. | |
virtual bool | isEmpty () const =0 |
Implemented in subclasses to return whether this item is empty, i.e. | |
virtual bool | hasHeightForWidth () const |
Returns true if this layout's preferred height depends on its width; otherwise returns false . | |
virtual int | heightForWidth (int) const |
Returns the preferred height for this layout item, given the width, which is not used in this default implementation. | |
virtual int | minimumHeightForWidth (int) const |
Returns the minimum height this widget needs for the given width, w. | |
virtual void | invalidate () |
Invalidates any cached information in this layout item. | |
virtual QWidget * | widget () const |
If this item manages a QWidget, returns that widget. | |
virtual QLayout * | layout () |
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned. | |
virtual QSpacerItem * | spacerItem () |
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned. | |
Qt::Alignment | alignment () const |
Returns the alignment of this item. | |
void | setAlignment (Qt::Alignment a) |
Sets the alignment of this item to alignment. | |
virtual QSizePolicy::ControlTypes | controlTypes () const |
Returns the control type(s) for the layout item. | |
Static Public Member Functions | |
static QSize | closestAcceptableSize (const QWidget *w, const QSize &s) |
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size. | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
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::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a 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 |
\reimp | |
void | addChildLayout (QLayout *l) |
This function is called from addLayout() or insertLayout() functions in subclasses to add layout childLayout as a sub-layout. | |
void | addChildWidget (QWidget *w) |
This function is called from addWidget() functions in subclasses to add w as a managed widget of a layout. | |
bool | adoptLayout (QLayout *layout) |
QRect | alignmentRect (const QRect &) const |
Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment(). | |
QLayout (QLayoutPrivate &d, QLayout *, QWidget *) | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
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 | |
QMargins | contentsMargins |
SizeConstraint | sizeConstraint |
the resize mode of the layout | |
![]() | |
QString | objectName |
the name of this object | |
Friends | |
class | QApplicationPrivate |
class | QWidget |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
Qt::Alignment | align |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
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/flowlayout}{Flow Layout} example for more information about implementing custom layout managers.
Geometry management stops when the layout manager is deleted.
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.
Enumerator | |
---|---|
SetDefaultConstraint | |
SetNoConstraint | |
SetMinimumSize | |
SetFixedSize | |
SetMaximumSize | |
SetMinAndMaxSize |
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().
Definition at line 83 of file qlayout.cpp.
QLayout::~QLayout | ( | ) |
Destroys the layout, deleting all child layouts. Geometry management stops when a top-level layout is deleted.
The layout classes will probably be fatally confused if you delete a sublayout.
Definition at line 699 of file qlayout.cpp.
References d, QObject::isWidgetType(), QWidget::layout(), layout(), QObject::parent(), parentWidget(), and removeItem().
|
protected |
Definition at line 93 of file qlayout.cpp.
References addItem(), d, invalidate(), QObject::objectName, Q_UNLIKELY, QT_CATCH, QT_RETHROW, QT_TRY, qUtf16Printable, qWarning, and QObject::setParent().
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.
Definition at line 994 of file qlayout.cpp.
References activate(), className, d, QWidgetPrivate::extra, QSize::height(), Qt::Horizontal, QWidget::isWindow(), metaObject(), QWidget::minimumSize, QObject::objectName, QObject::parent(), Q_UNLIKELY, qUtf16Printable, qWarning, SetDefaultConstraint, SetFixedSize, QWidget::setFixedSize(), QSize::setHeight(), SetMaximumSize, QWidget::setMaximumSize(), SetMinAndMaxSize, SetMinimumSize, QWidget::setMinimumSize(), SetNoConstraint, QSize::setWidth(), totalMaximumSize(), totalMinimumSize(), totalSizeHint(), QWidget::updateGeometry(), Qt::Vertical, and QSize::width().
Referenced by activate(), QWidgetPrivate::activateChildLayoutsRecursively(), QMessageBoxPrivate::layoutMinimumWidth(), QWidgetPrivate::prepareToRender(), QWidgetPrivate::setVisible(), QWidgetPrivate::show_recursive(), QComboBox::showPopup(), QMessageBoxPrivate::updateSize(), and widgetEvent().
This function is called from addLayout()
or insertLayout()
functions in subclasses to add layout childLayout 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.
Definition at line 718 of file qlayout.cpp.
References QObject::objectName, QObject::parent(), parentWidget(), Q_UNLIKELY, qUtf16Printable, qWarning, and QObject::setParent().
Referenced by adoptLayout().
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 produce 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 836 of file qlayout.cpp.
References QMetaObject::invokeMethod(), QWidget::isVisible(), QWidget::layout(), parentWidget(), QWidget::parentWidget(), Q_UNLIKELY, Qt::QueuedConnection, qUtf16Printable, qWarning, removeWidgetRecursively(), QWidget::testAttribute(), Qt::WA_LaidOut, and Qt::WA_WState_ExplicitShowHide.
Referenced by QGridLayout::addWidget(), QGridLayout::addWidget(), addWidget(), QStackedLayout::insertWidget(), QBoxLayout::insertWidget(), replaceWidget(), QMainWindowLayout::setCentralWidget(), setMenuBar(), and QDockWidgetLayout::setWidgetForRole().
|
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.
Implemented in QBoxLayout, QGridLayout, CardLayout, QFormLayout, QStackedLayout, QDockWidgetLayout, QMainWindowLayout, and QToolBarLayout.
Referenced by QLayout(), and addWidget().
Adds widget w to this layout in a manner specific to the layout.
This function uses addItem().
Definition at line 186 of file qlayout.cpp.
References addChildWidget(), addItem(), and QLayoutPrivate::createWidgetItem().
Referenced by DragWidget::DragWidget(), FinalWidget::FinalWidget(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), Window::Window(), dropevents::Window::Window(), QGridLayout::addWidget(), QPrintPreviewWidgetPrivate::init(), QKeySequenceEditPrivate::init(), and QMdiSubWindow::setWidget().
|
protected |
Definition at line 736 of file qlayout.cpp.
References addChildLayout(), layout(), ok, and QObject::parent().
Referenced by QGridLayout::addLayout(), QGridLayout::addLayout(), and QBoxLayout::insertLayout().
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 expandingDirections(). It is never larger than r.
Definition at line 1264 of file qlayout.cpp.
References Qt::AlignBottom, Qt::AlignHorizontal_Mask, Qt::AlignLeft, QLayoutItem::alignment(), Qt::AlignRight, Qt::AlignTop, Qt::AlignVertical_Mask, expandingDirections(), QLayoutItem::hasHeightForWidth(), QSize::height(), QLayoutItem::heightForWidth(), Qt::Horizontal, QGuiApplication::layoutDirection, maximumSize(), QObject::parent(), parentWidget(), qMin(), setAlignment(), QLayoutItem::sizeHint(), Qt::Vertical, QStyle::visualAlignment(), and QSize::width().
Referenced by QBoxLayout::setGeometry(), and QGridLayout::setGeometry().
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 559 of file qlayout.cpp.
References QEvent::ChildRemoved, d, e, and removeItem().
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.
Definition at line 1397 of file qlayout.cpp.
References QSize::boundedTo(), QSize::expandedTo(), QLayoutItem::hasHeightForWidth(), QSize::height(), QWidget::height, QWidget::layout(), QLayoutItem::minimumHeightForWidth(), qMax(), qMin(), qSmartMaxSize(), qSmartMinSize(), QWidget::size, QLayoutItem::widget(), QSize::width(), and QWidget::width.
Referenced by QWidgetWindowPrivate::closestAcceptableGeometry(), and QSizeGrip::mouseMoveEvent().
QMargins QLayout::contentsMargins | ( | ) | const |
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.
Definition at line 366 of file qlayout.cpp.
References getContentsMargins().
QRect QLayout::contentsRect | ( | ) | const |
Returns the layout's geometry() rectangle, but taking into account the contents margins.
Definition at line 381 of file qlayout.cpp.
References d, and getContentsMargins().
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 438 of file qlayout.cpp.
References QLayoutItem::controlTypes(), count(), QSizePolicy::DefaultType, i, and itemAt().
|
pure virtual |
Must be implemented in subclasses to return the number of items in the layout.
Implemented in CardLayout, QBoxLayout, QFormLayout, QGridLayout, QStackedLayout, QDockWidgetLayout, QMainWindowLayout, and QToolBarLayout.
Referenced by controlTypes(), indexOf(), indexOf(), and replaceWidget().
|
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}.
Implements QLayoutItem.
Reimplemented in QToolBarLayout.
Definition at line 943 of file qlayout.cpp.
References Qt::Horizontal, and Qt::Vertical.
Referenced by QWidgetPrivate::adjustedSize(), alignmentRect(), and QWidgetItem::expandingDirections().
|
overridevirtual |
\reimp
Implements QLayoutItem.
Definition at line 460 of file qlayout.cpp.
References d.
Referenced by QWidgetPrivate::safeAreaMargins(), QBoxLayout::setGeometry(), QGridLayout::setGeometry(), QDockWidgetLayout::setGeometry(), QFormLayout::setGeometry(), QStackedLayout::setStackingMode(), and QToolBarLayout::updateMacBorderMetrics().
void QLayout::getContentsMargins | ( | int * | left, |
int * | top, | ||
int * | right, | ||
int * | bottom | ||
) | const |
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.
Definition at line 347 of file qlayout.cpp.
References d, QStyle::PM_LayoutBottomMargin, QStyle::PM_LayoutLeftMargin, QStyle::PM_LayoutRightMargin, and QStyle::PM_LayoutTopMargin.
Referenced by contentsMargins(), contentsRect(), QFormLayout::heightForWidth(), QFontDialogPrivate::init(), and QFormLayout::setGeometry().
|
virtual |
Returns the index of layoutItem, or -1 if layoutItem is not found.
Reimplemented in QToolBarLayout.
Definition at line 1195 of file qlayout.cpp.
References count(), i, itemAt(), and layoutItem().
|
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().
Reimplemented in QToolBarLayout.
Definition at line 1176 of file qlayout.cpp.
References count(), i, itemAt(), and QLayoutItem::widget().
Referenced by QFormLayout::getWidgetPosition(), QMainWindowLayout::hover(), QWidgetPrivate::safeAreaMargins(), QStackedLayout::setCurrentWidget(), QToolBarLayout::setExpanded(), and QWizardPrivate::updateLayout().
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Reimplemented in QMainWindowLayout, and QToolBarLayout.
Definition at line 469 of file qlayout.cpp.
Referenced by QLayout(), QStackedLayout::insertWidget(), QBoxLayout::invalidate(), QFormLayout::invalidate(), QGridLayout::invalidate(), QMainWindowLayout::invalidate(), QToolBarLayout::invalidate(), QWidgetPrivate::prepareToRender(), removeItem(), removeWidget(), removeWidgetRecursively(), setAlignment(), setAlignment(), setContentsMargins(), QWidget::setLayout(), setSizeConstraint(), setSpacing(), QDockWidgetLayout::setVerticalTitleBar(), QDockWidgetLayout::setWidgetForRole(), QDockWidgetLayout::takeAt(), and QDockWidgetPrivate::updateButtons().
|
overridevirtual |
\reimp
Implements QLayoutItem.
Reimplemented in QToolBarLayout.
Definition at line 422 of file qlayout.cpp.
References i, item, and itemAt().
Referenced by QWidgetTextControlPrivate::isPreediting(), and QPlainTextEdit::paintEvent().
bool QLayout::isEnabled | ( | ) | const |
Returns true
if the layout is enabled; otherwise returns false
.
Definition at line 1385 of file qlayout.cpp.
References d.
|
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.
Implemented in QFormLayout, QGridLayout, QDockWidgetLayout, QMainWindowLayout, QToolBarLayout, CardLayout, QBoxLayout, and QStackedLayout.
Referenced by controlTypes(), indexOf(), indexOf(), isEmpty(), removeItem(), removeWidget(), removeWidgetRecursively(), replaceWidget(), setAlignment(), setAlignment(), and QToolBar::setIconSize().
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 297 of file qlayoutitem.cpp.
Referenced by ~QLayout(), QGridLayout::addLayout(), QGridLayout::addLayout(), QBoxLayout::addLayout(), QFormLayout::addRow(), adoptLayout(), QFormLayout::getLayoutPosition(), QBoxLayout::insertLayout(), QFormLayout::insertRow(), QFormLayout::isRowVisible(), QWidget::layout(), QMainWindowLayout::plug(), QFormLayout::removeRow(), QToolBarLayout::setExpanded(), QFormLayout::setLayout(), QFormLayout::setRowVisible(), QBoxLayout::setStretchFactor(), QFormLayout::takeRow(), QMainWindowLayout::unplug(), and update().
|
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.
Definition at line 926 of file qlayout.cpp.
References QLAYOUTSIZE_MAX.
Referenced by alignmentRect(), QToolBarLayout::layoutActions(), and totalMaximumSize().
QWidget * QLayout::menuBar | ( | ) | const |
Returns the menu bar set for this layout, or \nullptr if no menu bar is set.
Definition at line 894 of file qlayout.cpp.
References d.
|
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 QStackedLayout, QMainWindowLayout, and QToolBarLayout.
Definition at line 911 of file qlayout.cpp.
Referenced by QMdiSubWindow::minimumSizeHint(), and totalMinimumSize().
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.
Definition at line 399 of file qlayout.cpp.
References d, QObject::isWidgetType(), QObject::parent(), parentWidget(), Q_ASSERT, Q_UNLIKELY, and qWarning.
Referenced by ~QLayout(), addChildLayout(), addChildWidget(), alignmentRect(), QMainWindowLayout::animationFinished(), QMainWindowLayout::applyState(), QToolBarLayout::expandedSize(), QToolBarLayout::expandingDirections(), QMainWindowLayout::hover(), QToolBarLayout::layoutActions(), QDockWidgetLayout::maximumSize(), QDockWidgetLayout::minimumSize(), QDockWidgetLayout::minimumTitleWidth(), QToolBarLayout::movable(), QDockWidgetLayout::nativeWindowDeco(), parentWidget(), QMainWindowLayout::plug(), QMainWindowLayout::restoreState(), QWidgetPrivate::safeAreaMargins(), QStackedLayout::setCurrentIndex(), QToolBarLayout::setExpanded(), QBoxLayout::setGeometry(), QDockWidgetLayout::setGeometry(), QMainWindowLayout::setGeometry(), QToolBarLayout::setGeometry(), QDockWidgetLayout::setVerticalTitleBar(), QDockWidgetLayout::sizeFromContent(), QDockWidgetLayout::sizeHint(), QDockWidgetLayout::titleHeight(), totalHeightForWidth(), totalMaximumSize(), totalMinimumHeightForWidth(), totalMinimumSize(), totalSizeHint(), QToolBarLayout::updateMacBorderMetrics(), and QToolBarLayout::updateMarginAndSpacing().
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).
Definition at line 1350 of file qlayout.cpp.
References child, i, invalidate(), item, itemAt(), and takeAt().
Referenced by ~QLayout(), and childEvent().
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.
Definition at line 1322 of file qlayout.cpp.
References child, i, invalidate(), itemAt(), Q_UNLIKELY, qWarning, takeAt(), and QLayoutItem::widget().
Referenced by QToolBoxPrivate::_q_widgetDestroyed(), QMdiSubWindowPrivate::removeBaseWidget(), QMessageBox::setCheckBox(), QInputDialogPrivate::setInputWidget(), QWatermarkLabel::setSideWidget(), and QDockWidgetLayout::setWidgetForRole().
|
virtual |
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.
Definition at line 1089 of file qlayout.cpp.
References addChildWidget(), count(), d, Qt::FindChildrenRecursively, item, itemAt(), and QLayoutItem::setAlignment().
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 222 of file qlayout.cpp.
References QLayoutItem::alignment(), i, invalidate(), item, and itemAt().
void QLayoutItem::setAlignment | ( | Qt::Alignment | alignment | ) |
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 46 of file qlayoutitem.cpp.
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 199 of file qlayout.cpp.
References QLayoutItem::alignment(), i, invalidate(), item, and itemAt().
Referenced by alignmentRect(), QPrintPreviewDialogPrivate::init(), and QQuickLayoutAttached::setAlignment().
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.
Definition at line 313 of file qlayout.cpp.
References QMargins::bottom(), QMargins::left(), QMargins::right(), setContentsMargins(), and QMargins::top().
void QLayout::setContentsMargins | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom | ||
) |
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.
Definition at line 288 of file qlayout.cpp.
References d, and invalidate().
Referenced by QtPrivate::QColorShower::QColorShower(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), QWizardHeader::QWizardHeader(), QCalendarWidgetPrivate::createNavigationBar(), QPrintPreviewWidgetPrivate::init(), QKeySequenceEditPrivate::init(), QMainWindowPrivate::init(), QPrintPreviewDialogPrivate::init(), QDialogButtonBoxPrivate::initLayout(), QColorDialogPrivate::initWidgets(), QWizardPrivate::recreateLayout(), QToolBoxPrivate::relayout(), QCalendarPopup::setCalendarWidget(), setContentsMargins(), QMessageBoxPrivate::setupLayout(), unsetContentsMargins(), and QToolBarLayout::updateMarginAndSpacing().
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.
Definition at line 1374 of file qlayout.cpp.
References d.
\reimp
Implements QLayoutItem.
Reimplemented in QBoxLayout, QGridLayout, QDockWidgetLayout, QMainWindowLayout, QToolBarLayout, CardLayout, QFormLayout, and QStackedLayout.
Definition at line 451 of file qlayout.cpp.
References d.
Referenced by QBoxLayout::setGeometry(), QGridLayout::setGeometry(), QMainWindowLayout::setGeometry(), QToolBarLayout::setGeometry(), CardLayout::setGeometry(), and QFormLayout::setGeometry().
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 881 of file qlayout.cpp.
References addChildWidget(), d, and QLayoutItem::widget().
void QLayout::setSizeConstraint | ( | SizeConstraint | constraint | ) |
Definition at line 1240 of file qlayout.cpp.
References d, and invalidate().
Referenced by QInputDialogPrivate::ensureLayout(), QWizardPrivate::init(), QDockWidgetPrivate::init(), QColorDialogPrivate::initWidgets(), and QMessageBoxPrivate::setupLayout().
|
virtual |
Reimplemented in QBoxLayout, QGridLayout, and QFormLayout.
Definition at line 266 of file qlayout.cpp.
References d, invalidate(), and spacing.
Referenced by CardLayout::CardLayout(), CardLayout::CardLayout(), QComboBoxPrivateContainer::QComboBoxPrivateContainer(), and QToolBarLayout::updateMarginAndSpacing().
QLayout::SizeConstraint QLayout::sizeConstraint | ( | ) | const |
Definition at line 1250 of file qlayout.cpp.
References d.
|
virtual |
Reimplemented in QBoxLayout, QFormLayout, and QGridLayout.
Definition at line 255 of file qlayout.cpp.
References d, QStyle::PM_LayoutHorizontalSpacing, and qSmartSpacing().
|
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:
Implemented in QFormLayout, QGridLayout, QDockWidgetLayout, QMainWindowLayout, QToolBarLayout, CardLayout, QBoxLayout, and QStackedLayout.
Referenced by QMainWindowLayout::hover(), removeItem(), removeWidget(), and removeWidgetRecursively().
int QLayout::totalHeightForWidth | ( | int | w | ) | const |
Also takes contentsMargins and menu bar into account.
Definition at line 598 of file qlayout.cpp.
References QWidgetPrivate::bottommargin, d, QLayoutItem::heightForWidth(), QWidgetPrivate::leftmargin, menuBarHeightForWidth(), QObject::parent(), parentWidget(), QWidgetPrivate::rightmargin, and QWidgetPrivate::topmargin.
Referenced by QWidgetPrivate::adjustedSize(), QWidget::heightForWidth(), QWidgetItem::heightForWidth(), and QMessageBoxPrivate::updateSize().
QSize QLayout::totalMaximumSize | ( | ) | const |
Also takes contentsMargins and menu bar into account.
Definition at line 668 of file qlayout.cpp.
References QWidgetPrivate::bottommargin, d, QWidget::ensurePolished(), QWidgetPrivate::leftmargin, maximumSize(), menuBarHeightForWidth(), parentWidget(), QLAYOUTSIZE_MAX, qMin(), QWidgetPrivate::rightmargin, and QWidgetPrivate::topmargin.
Referenced by activate(), and QWizardPrivate::updateMinMaxSizes().
int QLayout::totalMinimumHeightForWidth | ( | int | w | ) | const |
Also takes contentsMargins and menu bar into account.
Definition at line 576 of file qlayout.cpp.
References QWidgetPrivate::bottommargin, d, QWidgetPrivate::leftmargin, menuBarHeightForWidth(), QLayoutItem::minimumHeightForWidth(), QObject::parent(), parentWidget(), QWidgetPrivate::rightmargin, and QWidgetPrivate::topmargin.
Referenced by QWidgetItem::minimumHeightForWidth().
QSize QLayout::totalMinimumSize | ( | ) | const |
Also takes contentsMargins and menu bar into account.
Definition at line 620 of file qlayout.cpp.
References QWidgetPrivate::bottommargin, d, QWidget::ensurePolished(), QWidgetPrivate::leftmargin, menuBarHeightForWidth(), minimumSize(), parentWidget(), QWidgetPrivate::rightmargin, and QWidgetPrivate::topmargin.
Referenced by activate(), QMessageBoxPrivate::layoutMinimumWidth(), QWizardHeader::setup(), QWizardPrivate::updateMinMaxSizes(), and QMessageBoxPrivate::updateSize().
QSize QLayout::totalSizeHint | ( | ) | const |
Also takes contentsMargins and menu bar into account.
Definition at line 643 of file qlayout.cpp.
References QWidgetPrivate::bottommargin, d, QWidget::ensurePolished(), QLayoutItem::hasHeightForWidth(), QLayoutItem::heightForWidth(), QWidgetPrivate::leftmargin, menuBarHeightForWidth(), parentWidget(), QWidgetPrivate::rightmargin, QLayoutItem::sizeHint(), and QWidgetPrivate::topmargin.
Referenced by activate(), and QWizardPrivate::updateMinMaxSizes().
void QLayout::unsetContentsMargins | ( | ) |
Unsets any user-defined margins around the layout. The layout will use the default values provided by the style.
Definition at line 326 of file qlayout.cpp.
References setContentsMargins().
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.
Definition at line 970 of file qlayout.cpp.
References QObject::isWidgetType(), layout(), QEvent::LayoutRequest, QObject::parent(), QCoreApplication::postEvent(), and Q_ASSERT.
Referenced by invalidate(), QVideoFrame::paint(), and QWidgetPrivate::updateContentsRect().
Performs child widget layout when the parent widget is resized. Also handles removal of widgets. e is the event
Definition at line 520 of file qlayout.cpp.
References activate(), child, QEvent::ChildRemoved, d, e, QObjectPrivate::get(), isVisible(), QEvent::LayoutRequest, QObject::parent(), removeWidgetRecursively(), QEvent::Resize, and QObjectData::wasWidget.
Referenced by QApplicationPrivate::notify_helper().
|
friend |
|
readwrite |
Definition at line 129 of file qlayout.h.
Referenced by QToolBarLayout::expandedSize(), QToolBarLayout::layoutActions(), QToolBarLayout::setGeometry(), and QCommonStyle::subElementRect().
|
readwrite |
the resize mode of the layout
The default mode is \l {QLayout::SetDefaultConstraint} {SetDefaultConstraint}.
|
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.
Definition at line 129 of file qlayout.h.
Referenced by CardLayout::CardLayout(), CardLayout::CardLayout(), QToolBarLayout::expandedSize(), QToolBarLayout::layoutActions(), CardLayout::minimumSize(), CardLayout::setGeometry(), setSpacing(), and CardLayout::sizeHint().