Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QLayoutItem Class Referenceabstract

The QLayoutItem class provides an abstract item that a QLayout manipulates. More...

#include <qlayoutitem.h>

+ Inheritance diagram for QLayoutItem:
+ Collaboration diagram for QLayoutItem:

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 QWidgetwidget () const
 If this item manages a QWidget, returns that widget.
 
virtual QLayoutlayout ()
 If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
 
virtual QSpacerItemspacerItem ()
 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
 

Detailed Description

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}.

See also
QLayout

Definition at line 24 of file qlayoutitem.h.

Constructor & Destructor Documentation

◆ QLayoutItem()

QLayoutItem::QLayoutItem ( Qt::Alignment alignment = Qt::Alignment())
inlineexplicit

Constructs a layout item with an alignment.

Not all subclasses support alignment.

Definition at line 53 of file qlayoutitem.h.

◆ ~QLayoutItem()

QLayoutItem::~QLayoutItem ( )
virtualdefault

Destroys the QLayoutItem.

Member Function Documentation

◆ alignment()

Qt::Alignment QLayoutItem::alignment ( ) const
inline

◆ controlTypes()

QSizePolicy::ControlTypes QLayoutItem::controlTypes ( ) const
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.

See also
QSizePolicy::controlType()

Reimplemented in QLayout, and QWidgetItem.

Definition at line 397 of file qlayoutitem.cpp.

References QSizePolicy::DefaultType.

Referenced by QFormLayoutItem::controlTypes().

+ Here is the caller graph for this function:

◆ expandingDirections()

Qt::Orientations QLayoutItem::expandingDirections ( ) const
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().

+ Here is the caller graph for this function:

◆ geometry()

QRect QLayoutItem::geometry ( ) const
pure virtual

Returns the rectangle covered by this layout item.

See also
setGeometry()

Implemented in QLayout, QSpacerItem, and QWidgetItem.

Referenced by QBoxLayoutPrivate::effectiveMargins(), QFormLayoutItem::geometry(), QWidgetPrivate::getOpaqueChildren(), and QBoxLayoutPrivate::setupGeom().

+ Here is the caller graph for this function:

◆ hasHeightForWidth()

bool QLayoutItem::hasHeightForWidth ( ) const
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.

See also
heightForWidth(), QWidget::heightForWidth()

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().

+ Here is the caller graph for this function:

◆ heightForWidth()

int QLayoutItem::heightForWidth ( int ) const
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:

int MyLayout::heightForWidth(int w) const
{
if (cache_dirty || cached_width != w) {
MyLayout *that = const_cast<MyLayout *>(this);
int h = calculateHeightForWidth(w);
that->cached_hfw = h;
return h;
}
return cached_hfw;
}

Caching is strongly recommended; without it layout will take exponential time.

See also
hasHeightForWidth()

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(), QLayout::totalHeightForWidth(), and QLayout::totalSizeHint().

+ Here is the caller graph for this function:

◆ invalidate()

void QLayoutItem::invalidate ( )
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 removeWidgetRecursively().

+ Here is the caller graph for this function:

◆ isEmpty()

bool QLayoutItem::isEmpty ( ) const
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().

+ Here is the caller graph for this function:

◆ layout()

QLayout * QLayoutItem::layout ( )
virtual

If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.

This function provides type-safe casting.

See also
spacerItem(), widget()

Reimplemented in QLayout.

Definition at line 278 of file qlayoutitem.cpp.

Referenced by QWidgetPrivate::activateChildLayoutsRecursively(), and QFormLayoutItem::layout().

+ Here is the caller graph for this function:

◆ maximumSize()

QSize QLayoutItem::maximumSize ( ) const
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().

+ Here is the caller graph for this function:

◆ minimumHeightForWidth()

int QLayoutItem::minimumHeightForWidth ( int w) const
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().

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

◆ minimumSize()

QSize QLayoutItem::minimumSize ( ) const
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(), QDockAreaLayout::minimumStableSize(), and QMdiAreaPrivate::rearrange().

+ Here is the caller graph for this function:

◆ setAlignment()

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 QGridBox::setAlignment().

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

◆ setGeometry()

void QLayoutItem::setGeometry ( const QRect & r)
pure virtual

Implemented in subclasses to set this item's geometry to r.

See also
geometry()

Implemented in QBoxLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, QDockWidgetLayout, QMainWindowLayout, QToolBarLayout, CardLayout, QFormLayout, and QStackedLayout.

Referenced by QMdiAreaPrivate::place(), QBoxLayout::setGeometry(), QFormLayoutItem::setGeometry(), and QGridBox::setGeometry().

+ Here is the caller graph for this function:

◆ sizeHint()

QSize QLayoutItem::sizeHint ( ) const
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(), QMdiArea::sizeHint(), and QLayout::totalSizeHint().

+ Here is the caller graph for this function:

◆ spacerItem()

QSpacerItem * QLayoutItem::spacerItem ( )
virtual

If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned.

This function provides type-safe casting.

See also
layout(), widget()

Reimplemented in QSpacerItem.

Definition at line 289 of file qlayoutitem.cpp.

Referenced by QBoxLayout::addSpacerItem(), changeSpacerSize(), QBoxLayout::insertSpacerItem(), and QWizardPrivate::updateLayout().

+ Here is the caller graph for this function:

◆ widget()

QWidget * QLayoutItem::widget ( ) const
virtual

If this item manages a QWidget, returns that widget.

Otherwise, \nullptr is returned.

Note
While the functions layout() and spacerItem() perform casts, this function returns another object: QLayout and QSpacerItem inherit QLayoutItem, while QWidget does not.
See also
layout(), spacerItem()

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(), 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(), QDialogButtonBoxPrivate::layoutButtons(), QDockAreaLayoutItem::maximumSize(), QDockAreaLayoutItem::minimumSize(), QStackedLayout::minimumSize(), QToolBarAreaLayoutInfo::moveToolBar(), QMainWindowLayout::plug(), QToolBarAreaLayoutItem::realSizeHint(), QFormLayout::removeRow(), QMdiArea::removeSubWindow(), QLayout::removeWidget(), removeWidgetRecursively(), 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(), QGraphicsProxyWidget::sizeHint(), QFormLayout::takeRow(), QMainWindowLayout::unplug(), QBoxLayoutItem::vStretch(), QGridBox::vStretch(), while(), QFormLayoutItem::widget(), and QStackedWidget::widget().

Member Data Documentation

◆ align

Qt::Alignment QLayoutItem::align
protected

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