Qt 4.8
Public Functions | Protected Variables | 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:
QLayout QSpacerItem QWidgetItem QBoxLayout QDockWidgetLayout QFormLayout QGridLayout QMainWindowLayout QStackedLayout QToolBarLayout QDockWidgetItem QToolBarItem QWidgetItemV2

Public Functions

Qt::Alignment alignment () const
 Returns the alignment of this item. More...
 
QSizePolicy::ControlTypes controlTypes () const
 Returns the control type(s) for the layout item. More...
 
virtual Qt::Orientations expandingDirections () const =0
 Returns whether this layout item can make use of more space than sizeHint(). More...
 
virtual QRect geometry () const =0
 Returns the rectangle covered by this layout item. More...
 
virtual bool hasHeightForWidth () const
 Returns true if this layout's preferred height depends on its width; otherwise returns false. More...
 
virtual int heightForWidth (int) const
 Returns the preferred height for this layout item, given the width w. More...
 
virtual void invalidate ()
 Invalidates any cached information in this layout item. More...
 
virtual bool isEmpty () const =0
 Implemented in subclasses to return whether this item is empty, i. More...
 
virtual QLayoutlayout ()
 If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned. More...
 
virtual QSize maximumSize () const =0
 Implemented in subclasses to return the maximum size of this item. More...
 
virtual int minimumHeightForWidth (int) const
 Returns the minimum height this widget needs for the given width, w. More...
 
virtual QSize minimumSize () const =0
 Implemented in subclasses to return the minimum size of this item. More...
 
 QLayoutItem (Qt::Alignment alignment=0)
 Constructs a layout item with an alignment. More...
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment. More...
 
virtual void setGeometry (const QRect &)=0
 Implemented in subclasses to set this item's geometry to r. More...
 
virtual QSize sizeHint () const =0
 Implemented in subclasses to return the preferred size of this item. More...
 
virtual QSpacerItemspacerItem ()
 If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned. More...
 
virtual QWidgetwidget ()
 If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned. More...
 
virtual ~QLayoutItem ()
 Destroys the QLayoutItem. More...
 

Protected Variables

Qt::Alignment align
 

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

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 Trading Height for Width.

See also
QLayout

Definition at line 64 of file qlayoutitem.h.

Constructors and Destructors

◆ QLayoutItem()

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

Constructs a layout item with an alignment.

Not all subclasses support alignment.

Definition at line 93 of file qlayoutitem.h.

94  : align(aalignment) { }
Qt::Alignment align
Definition: qlayoutitem.h:90

◆ ~QLayoutItem()

QLayoutItem::~QLayoutItem ( )
virtual

Destroys the QLayoutItem.

Definition at line 328 of file qlayoutitem.cpp.

329 {
330 }

Functions

◆ alignment()

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

◆ controlTypes()

QSizePolicy::ControlTypes QLayoutItem::controlTypes ( ) const

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

Definition at line 447 of file qlayoutitem.cpp.

Referenced by controlTypes(), QBoxLayoutPrivate::setupGeom(), and QGridLayoutPrivate::setupSpacings().

448 {
449  // ### Qt 5: This function should probably be virtual instead
450  if (const QWidget *widget = const_cast<QLayoutItem*>(this)->widget()) {
451  return widget->sizePolicy().controlType();
452  } else if (const QLayout *layout = const_cast<QLayoutItem*>(this)->layout()) {
453  if (layout->count() == 0)
455  QSizePolicy::ControlTypes types;
456  for (int i = layout->count() - 1; i >= 0; --i)
457  types |= layout->itemAt(i)->controlTypes();
458  return types;
459  }
461 }
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QSizePolicy::ControlTypes controlTypes() const
Returns the control type(s) for the layout item.
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
static const struct @32 types[]
virtual int count() const =0
Must be implemented in subclasses to return the number of items in the layout.
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:171
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
ControlType controlType() const
Definition: qlayout.cpp:1670

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

Referenced by QDockAreaLayoutItem::expansive(), QSpacerItem::QSpacerItem(), QWidgetItem::QWidgetItem(), QBoxLayoutPrivate::setupGeom(), updateFormLayoutItem(), and QWizardPrivate::updateLayout().

◆ geometry()

QRect QLayoutItem::geometry ( ) const
pure virtual

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

Definition at line 400 of file qlayoutitem.cpp.

Referenced by QWidgetPrivate::adjustedSize(), QLayout::closestAcceptableSize(), QWidgetPrivate::hasHeightForWidth(), QBoxLayoutItem::hfw(), QBoxLayoutItem::mhfw(), QtWndProc(), QWidgetItem::QWidgetItem(), QBoxLayout::setGeometry(), QWidgetItem::setGeometry(), QBoxLayoutPrivate::setupGeom(), updateFormLayoutItem(), QScrollAreaPrivate::updateScrollBars(), and QMessageBoxPrivate::updateSize().

401 {
402  return false;
403 }

◆ heightForWidth()

int QLayoutItem::heightForWidth ( int  ) const
virtual

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

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) {
// 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 QWidgetItemV2, QFormLayout, QWidgetItem, QGridLayout, QBoxLayout, and QStackedLayoutHFW.

Definition at line 434 of file qlayoutitem.cpp.

Referenced by QBoxLayoutItem::hfw(), QBoxLayoutItem::mhfw(), minimumHeightForWidth(), QWidgetItem::QWidgetItem(), QBoxLayout::setGeometry(), and QWidgetItem::setGeometry().

435 {
436  return -1;
437 }

◆ invalidate()

void QLayoutItem::invalidate ( )
virtual

Invalidates any cached information in this layout item.

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

Definition at line 335 of file qlayoutitem.cpp.

Referenced by QLayout::activateRecursiveHelper().

336 {
337 }

◆ isEmpty()

bool QLayoutItem::isEmpty ( ) const
pure virtual

◆ layout()

QLayout * QLayoutItem::layout ( )
virtual

◆ maximumSize()

QSize QLayoutItem::maximumSize ( ) const
pure virtual

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

Definition at line 410 of file qlayoutitem.cpp.

Referenced by QLayout::closestAcceptableSize().

411 {
412  return heightForWidth(w);
413 }
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width w.

◆ minimumSize()

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

Referenced by QToolBarLayout::createItem(), QBoxLayout::insertWidget(), and QLayout::setAlignment().

208 {
209  align = alignment;
210 }
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85
Qt::Alignment align
Definition: qlayoutitem.h:90

◆ setGeometry()

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

◆ sizeHint()

QSize QLayoutItem::sizeHint ( ) const
pure virtual

◆ spacerItem()

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.

Definition at line 352 of file qlayoutitem.cpp.

Referenced by changeSpacerSize(), QSpacerItem::QSpacerItem(), QBoxLayout::setDirection(), and QComboBoxPrivateContainer::updateTopBottomMargin().

353 {
354  return 0;
355 }

◆ widget()

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.

Definition at line 377 of file qlayoutitem.cpp.

Referenced by QGridLayoutPrivate::addData(), QStackedLayout::addItem(), QStackedLayout::addWidget(), QDockAreaLayoutInfo::apply(), QToolBarAreaLayout::apply(), QDockAreaLayout::apply(), QMainWindowLayoutState::centralWidget(), QMainWindowLayoutState::contains(), controlTypes(), QToolBarLayout::createItem(), QBoxLayoutPrivate::effectiveMargins(), QGridLayoutPrivate::effectiveMargins(), QToolBarAreaLayout::findToolBar(), QToolBarAreaLayoutLine::fitLayout(), fixToolBarOrientation(), QToolBarAreaLayout::getStyleOptionInfo(), QMainWindowLayout::hover(), QBoxLayoutItem::hStretch(), QLayout::indexOf(), QDockAreaLayoutInfo::indexOf(), QToolBarAreaLayout::indexOf(), QDockAreaLayoutInfo::info(), QDockAreaLayoutInfo::insertGap(), QMainWindowLayoutState::insertGap(), QToolBarAreaLayoutInfo::insertItem(), QToolBarAreaLayoutInfo::insertToolBarBreak(), QDialogButtonBoxPrivate::layoutButtons(), QDockAreaLayoutItem::maximumSize(), QStackedLayout::minimumSize(), QDockAreaLayoutItem::minimumSize(), QToolBarAreaLayoutInfo::moveToolBar(), QMainWindowLayout::plug(), QWidgetItem::QWidgetItem(), QToolBarAreaLayoutItem::realSizeHint(), QMainWindowLayoutState::remove(), QToolBarAreaLayoutInfo::removeToolBar(), QToolBarAreaLayoutInfo::removeToolBarBreak(), QLayout::removeWidget(), removeWidgetRecursively(), QLayoutPrivate::reparentChildWidgets(), QMainWindowLayout::revert(), QDockAreaLayoutInfo::saveState(), QAbstractScrollAreaScrollBarContainer::scrollBarLayoutIndex(), QLayout::setAlignment(), QWizardPrivate::setButtonLayout(), QStackedLayout::setCurrentIndex(), QStackedLayout::setGeometry(), QToolBar::setIconSize(), QDeclarativeView::setRootObject(), QStackedLayout::setStackingMode(), QBoxLayout::setStretchFactor(), QBoxLayoutPrivate::setupGeom(), QGridLayoutPrivate::setupSpacings(), QStackedLayout::sizeHint(), QDockAreaLayoutItem::sizeHint(), spacingHelper(), QMainWindowLayout::statusBar(), QDockAreaLayoutInfo::tab(), tabId(), QMainWindow::tabifiedDockWidgets(), QStackedLayout::takeAt(), QDockAreaLayoutInfo::takeAt(), QToolBarAreaLayout::toolBarBreak(), QDockAreaLayoutInfo::updateTabBar(), QBoxLayoutItem::vStretch(), QStackedWidget::widget(), QDockWidgetLayout::widgetForRole(), and QAbstractScrollAreaScrollBarContainer::widgets().

378 {
379  return 0;
380 }

Properties

◆ align

Qt::Alignment QLayoutItem::align
protected

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