Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 25 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 54 of file qlayoutitem.h.

◆ ~QLayoutItem()

QLayoutItem::~QLayoutItem ( )
virtualdefault

Destroys the QLayoutItem.

Member Function Documentation

◆ alignment()

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

Returns the alignment of this item.

Definition at line 46 of file qlayoutitem.h.

◆ 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 392 of file qlayoutitem.cpp.

◆ expandingDirections()

virtual 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, qdesigner_internal::PaddingSpacerItem, qdesigner_internal::PaddingSpacerItem, QFormLayout, QGridLayout, QLayout, QSpacerItem, QToolBarLayout, and QWidgetItem.

◆ geometry()

virtual QRect QLayoutItem::geometry ( ) const
pure virtual

Returns the rectangle covered by this layout item.

See also
setGeometry()

Implemented in QLayout, QSpacerItem, and QWidgetItem.

◆ 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, QStackedLayout, and QWidgetItem.

Definition at line 345 of file qlayoutitem.cpp.

◆ 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 QBoxLayout, QFormLayout, QGridLayout, QStackedLayout, QWidgetItem, and QWidgetItemV2.

Definition at line 379 of file qlayoutitem.cpp.

◆ 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 263 of file qlayoutitem.cpp.

◆ isEmpty()

virtual 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, QToolBarItem, QToolBarLayout, and QWidgetItem.

◆ 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 273 of file qlayoutitem.cpp.

◆ maximumSize()

virtual QSize QLayoutItem::maximumSize ( ) const
pure virtual

Implemented in subclasses to return the maximum size of this item.

Implemented in QBoxLayout, QDockWidgetItem, QDockWidgetLayout, QGridLayout, QLayout, QSpacerItem, QWidgetItem, and QWidgetItemV2.

◆ 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 355 of file qlayoutitem.cpp.

◆ minimumSize()

virtual QSize QLayoutItem::minimumSize ( ) const
pure virtual

◆ 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 151 of file qlayoutitem.cpp.

◆ setGeometry()

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

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

See also
geometry()

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

◆ sizeHint()

virtual QSize QLayoutItem::sizeHint ( ) const
pure virtual

◆ 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 284 of file qlayoutitem.cpp.

◆ 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 322 of file qlayoutitem.cpp.

Member Data Documentation

◆ align

Qt::Alignment QLayoutItem::align
protected

Definition at line 51 of file qlayoutitem.h.


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