QtBase  v6.3.1
Public Member Functions | Protected Attributes | List of all members
QLayoutItem Class Referenceabstract

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

#include <qlayoutitem.h>

Inheritance diagram for QLayoutItem:
Inheritance graph
[legend]
Collaboration diagram for QLayoutItem:
Collaboration graph
[legend]

Public Member Functions

 QLayoutItem (Qt::Alignment alignment=Qt::Alignment())
 
virtual ~QLayoutItem ()
 
virtual QSize sizeHint () const =0
 
virtual QSize minimumSize () const =0
 
virtual QSize maximumSize () const =0
 
virtual Qt::Orientations expandingDirections () const =0
 
virtual void setGeometry (const QRect &)=0
 
virtual QRect geometry () const =0
 
virtual bool isEmpty () const =0
 
virtual bool hasHeightForWidth () const
 
virtual int heightForWidth (int) const
 
virtual int minimumHeightForWidth (int) const
 
virtual void invalidate ()
 
virtual QWidgetwidget () const
 
virtual QLayoutlayout ()
 
virtual QSpacerItemspacerItem ()
 
Qt::Alignment alignment () const
 
void setAlignment (Qt::Alignment a)
 
virtual QSizePolicy::ControlTypes controlTypes () const
 

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

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 60 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 89 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 81 of file qlayoutitem.h.

Here is the caller graph for this function:

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

Definition at line 433 of file qlayoutitem.cpp.

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 LayoutItem, QToolBarLayout, QWidgetItem, QSpacerItem, QLayout, QGridLayout, QFormLayout, QBoxLayout, FlowLayout, and BorderLayout.

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 LayoutItem, QWidgetItem, QSpacerItem, and QLayout.

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

Definition at line 386 of file qlayoutitem.cpp.

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:

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

See also
hasHeightForWidth()

Reimplemented in QWidgetItem, QGridLayout, QBoxLayout, FlowLayout, QStackedLayout, QWidgetItemV2, and QFormLayout.

Definition at line 420 of file qlayoutitem.cpp.

Here is the caller graph for this function:

◆ invalidate()

void QLayoutItem::invalidate ( )
virtual

Invalidates any cached information in this layout item.

Reimplemented in MyLayout, QToolBarLayout, QMainWindowLayout, QLayout, QGridLayout, QFormLayout, and QBoxLayout.

Definition at line 304 of file qlayoutitem.cpp.

◆ 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 LayoutItem, QToolBarLayout, QToolBarItem, QWidgetItem, QSpacerItem, and QLayout.

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

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 LayoutItem, QDockWidgetItem, QDockWidgetLayout, QWidgetItemV2, QWidgetItem, QSpacerItem, QLayout, QGridLayout, and QBoxLayout.

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 QWidgetItem, QGridLayout, and QBoxLayout.

Definition at line 396 of file qlayoutitem.cpp.

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 LayoutItem, QToolBarLayout, QMainWindowLayout, QDockWidgetItem, QDockWidgetLayout, QStackedLayout, QWidgetItemV2, QWidgetItem, QSpacerItem, QLayout, QGridLayout, QFormLayout, QBoxLayout, CardLayout, FlowLayout, and BorderLayout.

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

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 QStackedLayout, QFormLayout, CardLayout, FlowLayout, BorderLayout, LayoutItem, QToolBarLayout, QMainWindowLayout, QDockWidgetLayout, QWidgetItem, QSpacerItem, QLayout, QGridLayout, and QBoxLayout.

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 MyLayout, LayoutItem, QToolBarLayout, QMainWindowLayout, QDockWidgetItem, QDockWidgetLayout, QStackedLayout, QWidgetItemV2, QWidgetItem, QSpacerItem, QGridLayout, QFormLayout, QBoxLayout, CardLayout, FlowLayout, and BorderLayout.

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

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

Here is the caller graph for this function:

Member Data Documentation

◆ align

Qt::Alignment QLayoutItem::align
protected

Definition at line 86 of file qlayoutitem.h.


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