![]() |
Qt 6.x
The Qt SDK
|
The QLayoutItem class provides an abstract item that a QLayout manipulates. More...
#include <qlayoutitem.h>
Public Member Functions | |
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. | |
Protected Attributes | |
Qt::Alignment | align |
The QLayoutItem class provides an abstract item that a QLayout manipulates.
\inmodule QtWidgets
This is used by custom layouts.
Pure virtual functions are provided to return information about the layout, including, sizeHint(), minimumSize(), maximumSize() and expandingDirections().
The layout's geometry can be set and retrieved with setGeometry() and geometry(), and its alignment with setAlignment() and alignment().
isEmpty() returns whether the layout item is empty. If the concrete item is a QWidget, it can be retrieved using widget(). Similarly for layout() and spacerItem().
Some layouts have width and height interdependencies. These can be expressed using hasHeightForWidth(), heightForWidth(), and minimumHeightForWidth(). For more explanation see the {Qt Quarterly} article \l{http://doc.qt.io/archives/qq/qq04-height-for-width.html}{Trading Height for Width}.
Definition at line 24 of file qlayoutitem.h.
|
inlineexplicit |
Constructs a layout item with an alignment.
Not all subclasses support alignment.
Definition at line 53 of file qlayoutitem.h.
|
virtualdefault |
Destroys the QLayoutItem.
|
inline |
Returns the alignment of this item.
Definition at line 45 of file qlayoutitem.h.
Referenced by QGridLayout::addItem(), QGridLayout::addLayout(), QGridLayout::addLayout(), QGridLayout::addWidget(), QGridLayout::addWidget(), QBoxLayout::addWidget(), QGridBox::alignment(), QLayout::alignmentRect(), QBoxLayout::insertWidget(), QBoxLayout::maximumSize(), QGridLayout::maximumSize(), QLayout::setAlignment(), setAlignment(), QLayout::setAlignment(), QFormLayout::setFormAlignment(), QBoxLayout::setGeometry(), QGridLayout::setGeometry(), and QFormLayout::setLabelAlignment().
|
virtual |
Returns the control type(s) for the layout item.
For a QWidgetItem, the control type comes from the widget's size policy; for a QLayoutItem, the control types is derived from the layout's contents.
Reimplemented in QLayout, and QWidgetItem.
Definition at line 397 of file qlayoutitem.cpp.
References QSizePolicy::DefaultType.
Referenced by QFormLayoutItem::controlTypes(), and QLayout::controlTypes().
|
pure virtual |
Returns whether this layout item 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.
Implemented in QBoxLayout, QFormLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, and QToolBarLayout.
Referenced by QFormLayoutItem::expandingDirections(), QGridBox::expandingDirections(), QDockAreaLayoutItem::expansive(), and QWizardPrivate::updateLayout().
|
pure virtual |
Returns the rectangle covered by this layout item.
Implemented in QLayout, QSpacerItem, and QWidgetItem.
Referenced by QBoxLayoutPrivate::effectiveMargins(), QFormLayoutItem::geometry(), QWidgetPrivate::getOpaqueChildren(), and QBoxLayoutPrivate::setupGeom().
|
virtual |
Returns true
if this layout's preferred height depends on its width; otherwise returns false
.
The default implementation returns false.
Reimplement this function in layout managers that support height for width.
Reimplemented in QBoxLayout, QFormLayout, QGridLayout, QWidgetItem, and QStackedLayout.
Definition at line 350 of file qlayoutitem.cpp.
Referenced by QWidgetPrivate::adjustedSize(), QLayout::alignmentRect(), QLayout::closestAcceptableSize(), QFormLayoutItem::hasHeightForWidth(), QGridBox::hasHeightForWidth(), QBoxLayoutItem::hfw(), QBoxLayoutItem::mhfw(), QLayout::totalSizeHint(), QScrollAreaPrivate::updateScrollBars(), and QMessageBoxPrivate::updateSize().
|
virtual |
Returns the preferred height for this layout item, given the width, which is not used in this default implementation.
The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the function hasHeightForWidth() will typically be much faster than calling this function and testing for -1.
Reimplement this function in layout managers that support height for width. A typical implementation will look like this:
Caching is strongly recommended; without it layout will take exponential time.
Reimplemented in QFormLayout, QWidgetItemV2, QStackedLayout, QBoxLayout, QGridLayout, and QWidgetItem.
Definition at line 384 of file qlayoutitem.cpp.
Referenced by QLayout::alignmentRect(), QGridBox::heightForWidth(), QFormLayoutItem::heightForWidth(), QBoxLayoutItem::hfw(), minimumHeightForWidth(), QMainWindowLayout::setGeometry(), QLayout::totalHeightForWidth(), and QLayout::totalSizeHint().
|
virtual |
Invalidates any cached information in this layout item.
Reimplemented in QBoxLayout, QFormLayout, QGridLayout, QLayout, QMainWindowLayout, and QToolBarLayout.
Definition at line 268 of file qlayoutitem.cpp.
Referenced by QFormLayoutPrivate::replaceAt().
|
pure virtual |
Implemented in subclasses to return whether this item is empty, i.e.
whether it contains any widgets.
Implemented in QLayout, QSpacerItem, QWidgetItem, QToolBarItem, and QToolBarLayout.
Referenced by QDockAreaLayout::apply(), QDockAreaLayout::getGrid(), QGridBox::isEmpty(), QDockAreaLayoutItem::skip(), and QToolBarAreaLayoutItem::skip().
|
virtual |
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
This function provides type-safe casting.
Reimplemented in QLayout.
Definition at line 278 of file qlayoutitem.cpp.
Referenced by QFormLayoutItem::layout(), org.qtproject.qt.android.QtLayout::onLayout(), and removeWidgetRecursively().
|
pure virtual |
Implemented in subclasses to return the maximum size of this item.
Implemented in QBoxLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, QWidgetItemV2, QDockWidgetLayout, and QDockWidgetItem.
Referenced by QDockAreaLayout::getGrid(), QGridBox::maximumSize(), and QDockAreaLayoutItem::maximumSize().
|
virtual |
Returns the minimum height this widget needs for the given width, w.
The default implementation simply returns heightForWidth(w).
Reimplemented in QBoxLayout, QGridLayout, and QWidgetItem.
Definition at line 360 of file qlayoutitem.cpp.
References heightForWidth().
Referenced by QLayout::closestAcceptableSize(), QBoxLayoutItem::mhfw(), QFormLayoutItem::minimumHeightForWidth(), and QLayout::totalMinimumHeightForWidth().
|
pure virtual |
Implemented in subclasses to return the minimum size of this item.
Implemented in CardLayout, QBoxLayout, QFormLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, QWidgetItemV2, QStackedLayout, QDockWidgetLayout, QDockWidgetItem, QMainWindowLayout, and QToolBarLayout.
Referenced by QDockAreaLayout::getGrid(), QBoxLayoutItem::mhfw(), QGridBox::minimumSize(), QDockAreaLayoutItem::minimumSize(), QDockAreaLayout::minimumSize(), QMainWindowLayoutState::minimumSize(), QMainWindowLayout::minimumSize(), QDockAreaLayout::minimumStableSize(), QMdiAreaPrivate::rearrange(), and QMainWindowLayout::setGeometry().
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 156 of file qlayoutitem.cpp.
References align, and alignment().
Referenced by QLayout::replaceWidget(), and QGridBox::setAlignment().
Implemented in subclasses to set this item's geometry to r.
Implemented in QBoxLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, QDockWidgetLayout, QMainWindowLayout, QToolBarLayout, CardLayout, QFormLayout, and QStackedLayout.
Referenced by QMdiAreaPrivate::place(), QFormLayoutItem::setGeometry(), QGridBox::setGeometry(), and QMainWindowLayout::setGeometry().
|
pure virtual |
Implemented in subclasses to return the preferred size of this item.
Implemented in CardLayout, QBoxLayout, QFormLayout, QGridLayout, QSpacerItem, QWidgetItem, QWidgetItemV2, QStackedLayout, QDockWidgetLayout, QDockWidgetItem, QMainWindowLayout, and QToolBarLayout.
Referenced by QLayout::alignmentRect(), QMdiAreaPrivate::appendChild(), QDockAreaLayout::getGrid(), QBoxLayoutItem::hfw(), QGridBox::sizeHint(), QDockAreaLayoutItem::sizeHint(), QDockAreaLayout::sizeHint(), QMainWindowLayoutState::sizeHint(), QMainWindowLayout::sizeHint(), QMdiArea::sizeHint(), and QLayout::totalSizeHint().
|
virtual |
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned.
This function provides type-safe casting.
Reimplemented in QSpacerItem.
Definition at line 289 of file qlayoutitem.cpp.
Referenced by QBoxLayout::addSpacerItem(), changeSpacerSize(), QBoxLayout::insertSpacerItem(), QWizardPrivate::updateLayout(), and QComboBoxPrivateContainer::updateTopBottomMargin().
|
virtual |
If this item manages a QWidget, returns that widget.
Otherwise, \nullptr is returned.
Reimplemented in QWidgetItem.
Definition at line 327 of file qlayoutitem.cpp.
Referenced by QStackedLayout::addItem(), QFormLayout::addRow(), QGridLayout::addWidget(), QGridLayout::addWidget(), QBoxLayout::addWidget(), QStackedLayout::addWidget(), QMainWindowLayout::animationFinished(), QDockAreaLayout::apply(), QMainWindowLayoutState::apply(), QLayout::closestAcceptableSize(), QMainWindowLayoutState::contains(), QBoxLayoutPrivate::effectiveMargins(), QFormLayout::getWidgetPosition(), QMainWindowLayout::hover(), QBoxLayoutItem::hStretch(), QGridBox::hStretch(), QLayout::indexOf(), QDockAreaLayoutInfo::insertGap(), QFormLayout::insertRow(), QStackedLayout::insertWidget(), QBoxLayout::insertWidget(), QFormLayout::isRowVisible(), QDockAreaLayoutItem::maximumSize(), QDockAreaLayoutItem::minimumSize(), QStackedLayout::minimumSize(), QToolBarAreaLayoutInfo::moveToolBar(), QMainWindowLayout::plug(), QToolBarAreaLayoutItem::realSizeHint(), QFormLayout::removeRow(), QMdiArea::removeSubWindow(), QLayout::removeWidget(), removeWidgetRecursively(), QStackedLayoutPrivate::replaceAt(), QMainWindowLayout::revert(), QMainWindowLayout::setCentralWidget(), QStackedLayout::setCurrentIndex(), QStackedLayout::setCurrentWidget(), QStackedLayout::setGeometry(), QLayout::setMenuBar(), QFormLayout::setRowVisible(), QStackedLayout::setStackingMode(), QBoxLayout::setStretchFactor(), QBoxLayoutPrivate::setupGeom(), QFormLayout::setWidget(), QDockAreaLayoutItem::sizeHint(), QStackedLayout::sizeHint(), spacingHelper(), QFormLayout::takeRow(), QMainWindowLayout::unplug(), QBoxLayoutItem::vStretch(), QGridBox::vStretch(), while(), QFormLayoutItem::widget(), and QStackedWidget::widget().
|
protected |
Definition at line 50 of file qlayoutitem.h.
Referenced by QWidgetItem::expandingDirections(), QWidgetItem::maximumSize(), setAlignment(), and QWidgetItem::setGeometry().