CopperSpice API  1.7.2
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 provides an abstract item that a QLayout manipulates. 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(). The function 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, and QLayout.

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

QRect QLayoutItem::geometry ( ) const
pure virtual

Returns the rectangle covered by this layout item.

See also
setGeometry()

Implemented in QWidgetItem, QLayout, and QSpacerItem.

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

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 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 width) const
{
if (cache_dirty || cached_width != w) {
// not all C++ compilers support "mutable"
MyLayout *that = (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, QWidgetItem, QStackedLayout, QBoxLayout, and QGridLayout.

void QLayoutItem::invalidate ( )
virtual

Invalidates any cached information in this layout item.

Reimplemented in QFormLayout, QLayout, QBoxLayout, and QGridLayout.

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

QLayout * QLayoutItem::layout ( )
virtual

If this item is a QLayout, it is returned as a QLayout, otherwise 0 is returned. This function provides type-safe casting.

Reimplemented in QLayout.

QSize QLayoutItem::maximumSize ( ) const
pure virtual

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

Implemented in QWidgetItem, QLayout, QSpacerItem, QBoxLayout, and QGridLayout.

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

QSize QLayoutItem::minimumSize ( ) const
pure virtual

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

Implemented in QFormLayout, QWidgetItem, QLayout, QSpacerItem, QStackedLayout, QBoxLayout, and QGridLayout.

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

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

See also
geometry()

Implemented in QFormLayout, QWidgetItem, QLayout, QGridLayout, QSpacerItem, QBoxLayout, and QStackedLayout.

QSize QLayoutItem::sizeHint ( ) const
pure virtual

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

Implemented in QFormLayout, QWidgetItem, QSpacerItem, QStackedLayout, QBoxLayout, and QGridLayout.

QSpacerItem * QLayoutItem::spacerItem ( )
virtual

If this item is a QSpacerItem, it is returned as a QSpacerItem, otherwise 0 is returned. This function provides type-safe casting.

Reimplemented in QSpacerItem.

QWidget * QLayoutItem::widget ( )
virtual

If this item is a QWidget, it is returned as a QWidget, otherwise 0 is returned. This function provides type-safe casting.

Reimplemented in QWidgetItem.