QLayoutItem 类

QLayoutItem class provides an abstract item that a QLayout 操纵。 更多...

头: #include <QLayoutItem>
qmake: QT += widgets
继承者:

QLayout , QSpacerItem ,和 QWidgetItem

公共函数

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 w ) const
virtual void invalidate ()
virtual bool isEmpty () const = 0
virtual QLayout * layout ()
virtual QSize maximumSize () const = 0
virtual int minimumHeightForWidth (int w ) const
virtual QSize minimumSize () const = 0
void setAlignment (Qt::Alignment alignment )
virtual void setGeometry (const QRect & r ) = 0
virtual QSize sizeHint () const = 0
virtual QSpacerItem * spacerItem ()
virtual QWidget * widget ()

详细描述

QLayoutItem class provides an abstract item that a QLayout 操纵。

这被用于自定义布局。

纯虚函数的提供以返回布局有关信息,包括: sizeHint (), minimumSize (), maximumSize () 及 expanding()。

可以设置和检索布局几何体采用 setGeometry () 和 geometry (),且其对齐采用 setAlignment () 和 alignment ().

isEmpty () 返回布局项目是否为空。若具体项是 QWidget ,它可以被检索使用 widget ()。同样,对于 layout () 和 spacerItem ().

某些布局的宽度和高度是相互依赖的。这些可以被表达,使用 hasHeightForWidth (), heightForWidth (),和 minimumHeightForWidth ()。更多解释见 Qt 季刊 文章 交易高度为宽度 .

另请参阅 QLayout .

成员函数文档编制

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

构造布局项采用 alignment 。并非所有子类都支持对齐。

[virtual] QLayoutItem:: ~QLayoutItem ()

销毁 QLayoutItem .

Qt::Alignment QLayoutItem:: alignment () const

返回此项的对齐方式。

另请参阅 setAlignment ().

[virtual] QSizePolicy::ControlTypes QLayoutItem:: controlTypes () const

返回布局项控件类型。对于 QWidgetItem , the control type comes from the widget's size policy; for a QLayoutItem , the control types is derived from the layout's contents.

另请参阅 QSizePolicy::controlType ().

[pure virtual] Qt::Orientations QLayoutItem:: expandingDirections () const

返回此布局项是否可以使用更多空间相比 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.

[pure virtual] QRect QLayoutItem:: geometry () const

返回此布局项所涵盖的矩形。

另请参阅 setGeometry ().

[virtual] bool QLayoutItem:: hasHeightForWidth () const

返回 true 若此布局的首选高度从属其宽度;否则返回 false 。默认实现返回 false。

重新实现此函数在支持高度为宽度的布局管理器中。

另请参阅 heightForWidth () 和 QWidget::heightForWidth ().

[virtual] int QLayoutItem:: heightForWidth ( int w ) const

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

默认实现返回 -1,指示首选高度独立于项宽度。使用函数 hasHeightForWidth () 通常比调用此函数快得多和测试为 -1。

重新实现此函数在支持高度为宽度的布局管理器中。典型实现看起来像这样:

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;
}
					

缓存是强烈推荐的;没有它,布局将花费指数级的时间。

另请参阅 hasHeightForWidth ().

[virtual] void QLayoutItem:: invalidate ()

使此布局项中的任何缓存信息无效。

[pure virtual] bool QLayoutItem:: isEmpty () const

在子类中实现以返回此项是否为空 (即:它是否包含任何 Widget)。

[virtual] QLayout *QLayoutItem:: layout ()

若此项是 QLayout ,它被返回作为 QLayout ; otherwise 0 is returned. This function provides type-safe casting.

另请参阅 spacerItem () 和 widget ().

[pure virtual] QSize QLayoutItem:: maximumSize () const

在子类中实现以返回此项的最大尺寸。

[virtual] int QLayoutItem:: minimumHeightForWidth ( int w ) const

返回此 Widget 所需的最小高度对于给定宽度, w 。默认实现只需返回 heightForWidth ( w ).

[pure virtual] QSize QLayoutItem:: minimumSize () const

在子类中实现以返回此项的最小尺寸。

void QLayoutItem:: setAlignment ( Qt::Alignment alignment )

把此项的对齐方式设为 alignment .

注意: 项对齐的支持仅通过 QLayoutItem 子类,哪里有视觉效果。除了 QSpacerItem ,为布局提供空白空间,所有公共 Qt 类继承 QLayoutItem 支持项对齐。

另请参阅 alignment ().

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

在子类中实现以将此项的几何体设为 r .

另请参阅 geometry ().

[pure virtual] QSize QLayoutItem:: sizeHint () const

在子类中实现以返回此项的首选大小。

[virtual] QSpacerItem *QLayoutItem:: spacerItem ()

若此项是 QSpacerItem ,它被返回作为 QSpacerItem ; otherwise 0 is returned. This function provides type-safe casting.

另请参阅 layout () 和 widget ().

[virtual] QWidget *QLayoutItem:: widget ()

若此项管理 QWidget ,返回该 Widget。否则, nullptr 被返回。

注意: 当函数 layout () 和 spacerItem () 履行铸造时,此函数返回另一对象: QLayout and QSpacerItem 继承 QLayoutItem ,而 QWidget 不会。

另请参阅 layout () 和 spacerItem ().