QLayoutItem Class Reference

[ QtGui module]

QLayoutItem 类提供抽象项 QLayout 操纵。 更多...

Inherited by QLayout , QSpacerItem and QWidgetItem .

方法


详细描述

QLayoutItem 类提供抽象项 QLayout 操纵。

这被用于自定义布局。

Pure virtual functions are provided to return information about the layout, including, sizeHint (), minimumSize (), maximumSize () 和 expanding().

The layout's geometry can be set and retrieved with setGeometry () 和 geometry (),且其对齐采用 setAlignment () 和 alignment ().

isEmpty () returns whether the layout item is empty. If the concrete item is a QWidget ,它可以被检索使用 widget ()。同样,对于 layout () 和 spacerItem ().

Some layouts have width and height interdependencies. These can be expressed using hasHeightForWidth (), heightForWidth (),和 minimumHeightForWidth (). For more explanation see the Qt 季刊 文章 Trading Height for Width .


方法文档编制

QLayoutItem.__init__ ( self , Qt.Alignment   alignment  = 0)

构造布局项采用 alignment . Not all subclasses support alignment.

QLayoutItem.__init__ ( self , QLayoutItem )

Qt.Alignment QLayoutItem.alignment ( self )

返回此项的对齐方式。

另请参阅 setAlignment ().

QSizePolicy.ControlTypes QLayoutItem.controlTypes ( self )

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.

另请参阅 QSizePolicy.controlType ().

Qt.Orientations QLayoutItem.expandingDirections ( self )

This method is abstract and should be reimplemented in any sub-class.

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.

QRect QLayoutItem.geometry ( self )

This method is abstract and should be reimplemented in any sub-class.

Returns the rectangle covered by this layout item.

另请参阅 setGeometry ().

bool QLayoutItem.hasHeightForWidth ( self )

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.

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

int QLayoutItem.heightForWidth ( self , int)

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.

另请参阅 hasHeightForWidth ().

QLayoutItem.invalidate ( self )

Invalidates any cached information in this layout item.

bool QLayoutItem.isEmpty ( self )

This method is abstract and should be reimplemented in any sub-class.

Implemented in subclasses to return whether this item is empty, i.e. whether it contains any widgets.

QLayout QLayoutItem.layout ( self )

若此项是 QLayout , it is returned as a QLayout ; otherwise 0 is returned. This function provides type-safe casting.

QSize QLayoutItem.maximumSize ( self )

This method is abstract and should be reimplemented in any sub-class.

Implemented in subclasses to return the maximum size of this 项。

int QLayoutItem.minimumHeightForWidth ( self , int)

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

QSize QLayoutItem.minimumSize ( self )

This method is abstract and should be reimplemented in any sub-class.

Implemented in subclasses to return the minimum size of this 项。

QLayoutItem.setAlignment ( self , Qt.Alignment   a )

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

注意: 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.

另请参阅 alignment ().

QLayoutItem.setGeometry ( self , QRect )

This method is abstract and should be reimplemented in any sub-class.

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

另请参阅 geometry ().

QSize QLayoutItem.sizeHint ( self )

This method is abstract and should be reimplemented in any sub-class.

Implemented in subclasses to return the preferred size of this 项。

QSpacerItem QLayoutItem.spacerItem ( self )

若此项是 QSpacerItem , it is returned as a QSpacerItem ; otherwise 0 is returned. This function provides type-safe casting.

QWidget QLayoutItem.widget ( self )

若此项是 QWidget , it is returned as a QWidget ; otherwise 0 is returned. This function provides type-safe casting.