CopperSpice API  1.9.1
QLayoutItem Class Referenceabstract

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

Inheritance diagram for QLayoutItem:
QLayout QSpacerItem QWidgetItem QBoxLayout QFormLayout QGridLayout QStackedLayout QHBoxLayout QVBoxLayout

Public Methods

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

Detailed Description

The QLayoutItem class is used by custom layouts.

Pure virtual methods 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(). The method 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().

See also
QLayout

Constructor & Destructor Documentation

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

Constructs a layout item with an alignment. Not all subclasses support alignment.

QLayoutItem::~QLayoutItem ( )
virtual

Destroys the QLayoutItem.

Method Documentation

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

Returns the alignment of this item.

See also
setAlignment()
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::controlTypes(), QLayout::controlTypes()

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 QFormLayout::expandingDirections(), QWidgetItem::expandingDirections(), QLayout::expandingDirections(), QSpacerItem::expandingDirections(), QBoxLayout::expandingDirections(), QGridLayout::expandingDirections()

QRect QLayoutItem::geometry ( ) const
pure virtual

Returns the rectangle covered by this layout item.

See also
setGeometry()

Implemented in QWidgetItem::geometry(), QLayout::geometry(), QSpacerItem::geometry()

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. Override this method in layout managers which support height for width.

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

Reimplemented in QFormLayout::hasHeightForWidth(), QWidgetItem::hasHeightForWidth(), QStackedLayout::hasHeightForWidth(), QBoxLayout::hasHeightForWidth(), QGridLayout::hasHeightForWidth()

int QLayoutItem::heightForWidth ( int  width) const
virtual

Returns the preferred height for this layout item, given the width.

The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the method hasHeightForWidth() will typically be much faster than calling this method and testing for -1.

Override this method in layout managers which support height for width. The following example shows a typical implementation.

// m_cached_hfw should be declared mutable in MyLayout
int MyLayout::heightForWidth(int width) const
{
if (cache_dirty || cached_width != w) {
int h = calculateHeightForWidth(w);
m_cached_hfw = h;
return h;
}
return m_cached_hfw;
}

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

See also
hasHeightForWidth()

Reimplemented in QFormLayout::heightForWidth(), QWidgetItem::heightForWidth(), QStackedLayout::heightForWidth(), QBoxLayout::heightForWidth(), QGridLayout::heightForWidth()

void QLayoutItem::invalidate ( )
virtual

Invalidates any cached information in this layout item.

Reimplemented in QFormLayout::invalidate(), QLayout::invalidate(), QBoxLayout::invalidate(), QGridLayout::invalidate()

bool QLayoutItem::isEmpty ( ) const
pure virtual

Override this method and return whether this item is empty or contains any widgets.

Implemented in QWidgetItem::isEmpty(), QLayout::isEmpty(), QSpacerItem::isEmpty()

QLayout * QLayoutItem::layout ( )
virtual

If this item contains a QLayout, then a pointer to the QLayout is returned, otherwise a nullptr is returned.

Reimplemented in QLayout::layout()

QSize QLayoutItem::maximumSize ( ) const
pure virtual

Override this method to return the maximum size of this item.

Implemented in QWidgetItem::maximumSize(), QLayout::maximumSize(), QSpacerItem::maximumSize(), QBoxLayout::maximumSize(), QGridLayout::maximumSize()

int QLayoutItem::minimumHeightForWidth ( int  width) const
virtual

Returns the minimum height this widget needs for the given width. The default implementation simply returns heightForWidth(width).

Reimplemented in QBoxLayout::minimumHeightForWidth(), QGridLayout::minimumHeightForWidth()

QSize QLayoutItem::minimumSize ( ) const
pure virtual
void QLayoutItem::setAlignment ( Qt::Alignment  alignment)

Sets the alignment of this item to alignment. Item alignment is only supported by some child classes.

See also
alignment()
void QLayoutItem::setGeometry ( const QRect rect)
pure virtual
QSize QLayoutItem::sizeHint ( ) const
pure virtual
QSpacerItem * QLayoutItem::spacerItem ( )
virtual

If this item contains a QSpacerItem, then a pointer to the QSpacerItem is returned, otherwise a nullptr is returned.

Reimplemented in QSpacerItem::spacerItem()

QWidget * QLayoutItem::widget ( )
virtual

If this item contains a QWidget, then a pointer to the QWidget is returned, otherwise a nullptr is returned.

Reimplemented in QWidgetItem::widget()