QtBase
v6.3.1
|
The QLayout class is the base class of geometry managers. More...
#include <qlayout.h>
Public Types | |
enum | SizeConstraint { SetDefaultConstraint , SetNoConstraint , SetMinimumSize , SetFixedSize , SetMaximumSize , SetMinAndMaxSize } |
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 | |
QObject * | sender () 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< QObjectData > | d_ptr |
Protected Attributes inherited from QLayoutItem | |
Qt::Alignment | align |
Related Functions inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
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.
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 120 of file qlayout.cpp.
QLayout::~QLayout | ( | ) |
|
protected |
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 1028 of file qlayout.cpp.
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.
Definition at line 753 of file qlayout.cpp.
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.
|
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 QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QStackedLayout, QFormLayout, CardLayout, FlowLayout, BorderLayout, MyLayout, QGridLayout, and QBoxLayout.
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.
|
protected |
Definition at line 771 of file qlayout.cpp.
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.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 594 of file qlayout.cpp.
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.
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 403 of file qlayout.cpp.
QRect QLayout::contentsRect | ( | ) | const |
Returns the layout's geometry() rectangle, but taking into account the contents margins.
Definition at line 418 of file qlayout.cpp.
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 475 of file qlayout.cpp.
|
pure virtual |
Must be implemented in subclasses to return the number of items in the layout.
Implemented in MyLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QStackedLayout, QGridLayout, QFormLayout, QBoxLayout, CardLayout, FlowLayout, BorderLayout, and FlowLayout.
|
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 977 of file qlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayoutItem.
Definition at line 497 of file qlayout.cpp.
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 384 of file qlayout.cpp.
|
virtual |
Returns the index of layoutItem, or -1 if layoutItem is not found.
Definition at line 1229 of file qlayout.cpp.
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.
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Reimplemented in MyLayout, QToolBarLayout, and QMainWindowLayout.
Definition at line 506 of file qlayout.cpp.
|
overridevirtual |
\reimp
Implements QLayoutItem.
Reimplemented in QToolBarLayout.
Definition at line 459 of file qlayout.cpp.
bool QLayout::isEnabled | ( | ) | const |
Returns true
if the layout is enabled; otherwise returns false
.
Definition at line 1419 of file qlayout.cpp.
|
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 MyLayout, QStackedLayout, QBoxLayout, CardLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, QFormLayout, FlowLayout, BorderLayout, and FlowLayout.
|
overridevirtual |
\reimp
Reimplemented from QLayoutItem.
Definition at line 333 of file qlayoutitem.cpp.
|
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.
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.
|
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.
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 436 of file qlayout.cpp.
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 1384 of file qlayout.cpp.
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 1356 of file qlayout.cpp.
|
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 1123 of file qlayout.cpp.
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.
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.
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.
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 350 of file qlayout.cpp.
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 325 of file qlayout.cpp.
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 1408 of file qlayout.cpp.
\reimp
Implements QLayoutItem.
Reimplemented in QStackedLayout, QFormLayout, CardLayout, FlowLayout, BorderLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, and QBoxLayout.
Definition at line 488 of file qlayout.cpp.
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.
void QLayout::setSizeConstraint | ( | SizeConstraint | constraint | ) |
Definition at line 1274 of file qlayout.cpp.
|
virtual |
Reimplemented in QFormLayout, QGridLayout, and QBoxLayout.
Definition at line 303 of file qlayout.cpp.
QLayout::SizeConstraint QLayout::sizeConstraint | ( | ) | const |
Definition at line 1284 of file qlayout.cpp.
|
virtual |
Reimplemented in QGridLayout, QFormLayout, and QBoxLayout.
Definition at line 292 of file qlayout.cpp.
|
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 MyLayout, QStackedLayout, QBoxLayout, CardLayout, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QGridLayout, QFormLayout, FlowLayout, and BorderLayout.
int QLayout::totalHeightForWidth | ( | int | w | ) | const |
Definition at line 633 of file qlayout.cpp.
QSize QLayout::totalMaximumSize | ( | ) | const |
Definition at line 703 of file qlayout.cpp.
int QLayout::totalMinimumHeightForWidth | ( | int | w | ) | const |
QSize QLayout::totalMinimumSize | ( | ) | const |
Definition at line 655 of file qlayout.cpp.
QSize QLayout::totalSizeHint | ( | ) | const |
Definition at line 678 of file qlayout.cpp.
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 363 of file qlayout.cpp.
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 1004 of file qlayout.cpp.
|
friend |
|
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.