[QtGui module]

The QLayout class is the base class of geometry managers. More…

Inherits QObject and QLayoutItem.

Inherited by QBoxLayout, QFormLayout, QGridLayout and QStackedLayout.

Types

  • enum SizeConstraint { SetDefaultConstraint, SetNoConstraint, SetMinimumSize, SetFixedSize, SetMaximumSize, SetMinAndMaxSize }

Methods

  • __init__ (self, QWidget parent)
  • __init__ (self)
  • bool activate (self)
  • addChildLayout (self, QLayout l)
  • addChildWidget (self, QWidget w)
  • addItem (self, QLayoutItem)
  • addWidget (self, QWidget w)
  • QRect alignmentRect (self, QRect)
  • childEvent (self, QChildEvent e)
  • QMargins contentsMargins (self)
  • QRect contentsRect (self)
  • int count (self)
  • Qt.Orientations expandingDirections (self)
  • QRect geometry (self)
  • (int left, int top, int right, int bottom) getContentsMargins (self)
  • int indexOf (self, QWidget)
  • invalidate (self)
  • bool isEmpty (self)
  • bool isEnabled (self)
  • QLayoutItem itemAt (self, int index)
  • QLayout layout (self)
  • int margin (self)
  • QSize maximumSize (self)
  • QWidget menuBar (self)
  • QSize minimumSize (self)
  • QWidget parentWidget (self)
  • removeItem (self, QLayoutItem)
  • removeWidget (self, QWidget w)
  • bool setAlignment (self, QWidget w, Qt.Alignment alignment)
  • bool setAlignment (self, QLayout l, Qt.Alignment alignment)
  • setAlignment (self, Qt.Alignment alignment)
  • setContentsMargins (self, int left, int top, int right, int bottom)
  • setContentsMargins (self, QMargins margins)
  • setEnabled (self, bool)
  • setGeometry (self, QRect)
  • setMargin (self, int)
  • setMenuBar (self, QWidget w)
  • setSizeConstraint (self, SizeConstraint)
  • setSpacing (self, int)
  • SizeConstraint sizeConstraint (self)
  • int spacing (self)
  • QLayoutItem takeAt (self, int index)
  • int totalHeightForWidth (self, int w)
  • QSize totalMaximumSize (self)
  • QSize totalMinimumSize (self)
  • QSize totalSizeHint (self)
  • update (self)
  • widgetEvent (self, QEvent)

Static Methods

  • QSize closestAcceptableSize (QWidget w, QSize s)

Special Methods

  • __len__ (self)

Detailed Description

该QLayout类是几何管理者的基类。

这是继承的具体类的抽象基类QBoxLayoutQGridLayoutQFormLayoutQStackedLayout

有关的QLayout子类或用户QMainWindow里面很少有任何需要使用由QLayout提供的基本功能,如setSizeConstraint()或setMenuBar( ) 。看Layout Management了解更多信息。

为了使自己的布局管理器,实现功能addItem( )sizeHint( )setGeometry( )itemAt()和takeAt( ) 。你也应该实施minimumSize( ),以确保你的布局是不是调整到零尺寸,如果有空间太少。为了支持儿童,其高度依赖于它们的宽度,实施hasHeightForWidth()和heightForWidth( ) 。请参阅Border LayoutFlow Layout示例有关实现自定义布局管理器的更多信息。

当布局管理器被删除几何管理停止。


Type Documentation

  1. QLayout.SizeConstraint

可能的值有:

Constant Value Description
QLayout.SetDefaultConstraint 0 主窗口部件的最小大小设置为minimumSize
()中,除插件已经具有的最小尺寸。
QLayout.SetFixedSize 3 主窗口部件的大小设置为sizeHint
();它不能在所有的调整大小。
QLayout.SetMinimumSize 2 主窗口部件的最小大小设置为minimumSize
();它不能是较小的。
QLayout.SetMaximumSize 4 主窗口部件的最大大小设置为maximumSize
();它不能大。
QLayout.SetMinAndMaxSize 5 主窗口部件的最小大小设置为minimumSize
() ,其最大尺寸设定为maximumSize
( ) 。
QLayout.SetNoConstraint 1 窗口小部件不受限。

See also setSizeConstraint( ) 。


Method Documentation

  1. QLayout.__init__ (self, QWidget parent)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个新的顶级QLayout,与父parentparent可能不是0 。

只能有一个是一个小部件的顶层布局。它是由返回QWidget.layout( ) 。

  1. QLayout.__init__ (self)

构造一个新的子QLayout

这种布局有被插入到另一个布局之前几何管理将工作。

  1. bool QLayout.activate (self)

重做的布局parentWidget()如果需要的话。

你通常应该不需要调用这个,因为它是自动调用在最适当的时候。如果布局被再做它返回True 。

See also update()和QWidget.updateGeometry( ) 。

  1. QLayout.addChildLayout (self, QLayout l)

l说法有它的所有权转移给Qt的。

此功能是从所谓的addLayout() or insertLayout()在子类的功能来添加布局l作为子布局。

在其中你需要把它直接调用的唯一情况是,如果你执行一个支持嵌套的布局自定义布局。

See also QBoxLayout.addLayout( )QBoxLayout.insertLayout()和QGridLayout.addLayout( ) 。

  1. QLayout.addChildWidget (self, QWidget w)

w说法有它的所有权转移给Qt的。

此功能是从所谓的addWidget()在子类中添加功能w作为布局的一个管理部件。

If w已通过布局管理,此功能将给予警告并删除w从布局。这个功能,因此必须加入之前调用w到布局的数据结构。

  1. QLayout.addItem (self, QLayoutItem)

这种方法是抽象的,应在任何子类中重新实现。

QLayoutItem说法有它的所有权转移给Qt的。

实现在子类中添加一个item。它是如何添加特定于每个子类。

这个功能并不是通常所说的应用程序代码。以一个小部件添加到布局,使用addWidget( )函数;有关规定增加一个子布局,使用addLayout ( )函数QLayout子类。

Note:所有权item被转移到布局,它的布局的责任将其删除。

See also addWidget( )QBoxLayout.addLayout()和QGridLayout.addLayout( ) 。

  1. QLayout.addWidget (self, QWidget w)

w说法有它的所有权转移给Qt的。

添加小工具w在特定的布局方式这样的布局。此函数使用addItem( ) 。

  1. QRect QLayout.alignmentRect (self, QRect)

返回时,此布局的几何形状被设置为应涵盖的矩形r,但前提是这个布局支持setAlignment( ) 。

其结果是衍生自sizeHint( )和扩展( ) 。这是从来没有大于r

  1. QLayout.childEvent (self, QChildEvent e)

从重新实现QObject.childEvent( ) 。

  1. QSize QLayout.closestAcceptableSize (QWidget w, QSize s)

返回一个大小满足所有尺寸的限制widget包括heightForWidth( ),并且是尽可能接近到size

  1. QMargins QLayout.contentsMargins (self)

[

返回周围的布局中使用的利润。

](docs_qmargins.html)

默认情况下,QLayout使用由式所提供的值。在大多数平台上,保证金是在所有方向11像素。

此功能被引入Qt的4.6 。

See also setContentsMargins( ) 。

  1. QRect QLayout.contentsRect (self)

返回布局的geometry( )的矩形,但考虑到内容的利润率。

此功能被引入Qt的4.3 。

See also setContentsMargins()和getContentsMargins( ) 。

  1. int QLayout.count (self)

这种方法是抽象的,应在任何子类中重新实现。

必须在子类中实现返回布局的项目数。

See also itemAt( ) 。

  1. Qt.Orientations QLayout.expandingDirections (self)

从重新实现QLayoutItem.expandingDirections( ) 。

返回此布局是否可以使更多的空间比使用sizeHint( ) 。的值Qt.Vertical or Qt.Horizontal意味着它要在只有一维增长,而Qt.Vertical|Qt.Horizontal也就是说,它要在这两个方面的增长。

默认实现返回Qt.Horizontal|Qt.Vertical。子类重新实现它返回基于其子控件的一个有意义的值size policies

See also sizeHint( ) 。

  1. QRect QLayout.geometry (self)

从重新实现QLayoutItem.geometry( ) 。

See also setGeometry( ) 。

  1. (int left, int top, int right, int bottom) QLayout.getContentsMargins (self)

提取左,上,右,和周围的布局中使用上下边界,并为它们分配到left_toprightbottom_(除非他们是空指针) 。

默认情况下,QLayout使用由式所提供的值。在大多数平台上,保证金是在所有方向11像素。

此功能被引入Qt的4.3 。

See also setContentsMargins( )QStyle.pixelMetric( )PM_LayoutLeftMarginPM_LayoutTopMarginPM_LayoutRightMarginPM_LayoutBottomMargin

  1. int QLayout.indexOf (self, QWidget)

搜索小工具widget在这种布局(不包括子布局) 。

返回的索引widget,或-1,如果widget是没有找到。

对所有项目使用默认的实现迭代itemAt( )

  1. QLayout.invalidate (self)

从重新实现QLayoutItem.invalidate( ) 。

  1. bool QLayout.isEmpty (self)

从重新实现QLayoutItem.isEmpty( ) 。

  1. bool QLayout.isEnabled (self)

返回True如果启用了布局,否则返回False 。

See also setEnabled( ) 。

  1. QLayoutItem QLayout.itemAt (self, int index)

[

这种方法是抽象的,应在任何子类中重新实现。

必须在子类中实现,以在返回版面项目index。如果不存在这样的产品,该函数必须返回0。项目从0连续编号。如果一个项目被删除,其他项目将被重新编号。

此功能可用于迭代的布局。下面的代码将绘制在小部件的布局结构为每个布局项目的矩形。

](docs_qlayoutitem.html)

  1. static void paintLayout(QPainter *painter, [QLayoutItem](docs_qlayoutitem.html) *item)
  2. {
  3. [QLayout](docs_qlayout.html) *layout = item->layout();
  4. if (layout) {
  5. for (int i = 0; i < layout->count(); ++i)
  6. paintLayout(painter, layout->itemAt(i));
  7. }
  8. painter->drawRect(item->geometry());
  9. }
  10. void MyWidget.paintEvent([QPaintEvent](docs_qpaintevent.html) *)
  11. {
  12. [QPainter](docs_qpainter.html) painter(this);
  13. if (layout())
  14. paintLayout(&painter, layout());
  15. }

See also count()和takeAt( ) 。

  1. QLayout QLayout.layout (self)

从重新实现QLayoutItem.layout( ) 。

  1. int QLayout.margin (self)
  1. QSize QLayout.maximumSize (self)

从重新实现QLayoutItem.maximumSize( ) 。

返回此布局的最大尺寸。这是该布局可以有同时仍尊重规格的最大尺寸。

返回值不包括所需的空间QWidget.setContentsMargins()或menuBar( ) 。

默认实现允许无限制调整大小。

  1. QWidget QLayout.menuBar (self)

[

返回菜单栏设置此布局,或者0,如果没有菜单栏设置。

](docs_qwidget.html)

See also setMenuBar( ) 。

  1. QSize QLayout.minimumSize (self)

从重新实现QLayoutItem.minimumSize( ) 。

返回此布局的最小尺寸。这是该布局可以有同时仍尊重的规格的最小尺寸。

返回值不包括所需的空间QWidget.setContentsMargins()或menuBar( ) 。

默认实现允许无限制调整大小。

  1. QWidget QLayout.parentWidget (self)

[

返回此布局,或0的父控件,如果这个布局上没有任何部件安装。

如果布局是一个子布局,该函数返回父布局的父控件。

](docs_qwidget.html)

See also parent( ) 。

  1. QLayout.removeItem (self, QLayoutItem)

QLayoutItem争论

删除布局项目item从布局。它是调用者的责任要删除的项目。

请注意,item可以是一个布局(自QLayout继承QLayoutItem) 。

See also removeWidget()和addItem( ) 。

  1. QLayout.removeWidget (self, QWidget w)

删除小工具widget从布局。此调用后,它是调用者的责任给小部件合理的几何形状或把小工具放回布局。

Note:所有权widget保持不变它被加入时相同。

See also removeItem( )QWidget.setGeometry()和addWidget( ) 。

  1. bool QLayout.setAlignment (self, QWidget w, Qt.Alignment alignment)

设置对齐部件walignment并返回True ,如果w在这种布局(不包括子布局)被发现,否则返回False 。

  1. bool QLayout.setAlignment (self, QLayout l, Qt.Alignment alignment)

设置此项目的对齐方式alignment

See also QLayoutItem.setAlignment( ) 。

  1. QLayout.setAlignment (self, Qt.Alignment alignment)

这是一个重载函数。

设置对齐布局lalignment并返回True ,如果l在这种布局(不包括子布局)被发现,否则返回False 。

  1. QLayout.setContentsMargins (self, int left, int top, int right, int bottom)

设置lefttoprightbottom利润使用周围的布局。

默认情况下,QLayout使用由式所提供的值。在大多数平台上,保证金是在所有方向11像素。

此功能被引入Qt的4.3 。

See also contentsMargins( )getContentsMargins( )QStyle.pixelMetric( )PM_LayoutLeftMarginPM_LayoutTopMarginPM_LayoutRightMarginPM_LayoutBottomMargin

  1. QLayout.setContentsMargins (self, QMargins margins)

设置margins使用周围的布局。

默认情况下,QLayout使用由式所提供的值。在大多数平台上,保证金是在所有方向11像素。

此功能被引入Qt的4.6 。

See also contentsMargins( ) 。

  1. QLayout.setEnabled (self, bool)

启用此布局,如果enable是真,否则禁用它。

已启用的布局动态调整的变化,而停用的布局行为,就好像它不存在。

默认情况下所有版面已启用。

See also isEnabled( ) 。

  1. QLayout.setGeometry (self, QRect)

从重新实现QLayoutItem.setGeometry( ) 。

See also geometry( ) 。

  1. QLayout.setMargin (self, int)
  1. QLayout.setMenuBar (self, QWidget w)

w说法有它的所有权转移给Qt的。

告诉几何管理器放置在菜单栏widget在顶部parentWidget( ) ,外QWidget.contentsMargins( ) 。所有子控件放置在菜单栏的底部边缘下方。

See also menuBar( ) 。

  1. QLayout.setSizeConstraint (self, SizeConstraint)
  1. QLayout.setSpacing (self, int)
  1. SizeConstraint QLayout.sizeConstraint (self)

[

  1. int QLayout.spacing (self)

](docs_qlayout.html#SizeConstraint-enum)

  1. QLayoutItem QLayout.takeAt (self, int index)

[

这种方法是抽象的,应在任何子类中重新实现。

QLayoutItem结果

必须在子类中实现以除去布局项目index从布局,并返回该项目。如果没有这样的项目,该函数必须什么也不做,返回0 。项目从0连续编号。如果一个项目被删除,其他项目将被重新编号。

下面的代码片段显示了一个安全的方式从布局中删除的所有项目:

](docs_qlayoutitem.html)

  1. QLayoutItem *child;
  2. while ((child = layout->takeAt(0)) != 0) {
  3. ...
  4. delete child;
  5. }

See also itemAt()和count( ) 。

  1. int QLayout.totalHeightForWidth (self, int w)
  1. QSize QLayout.totalMaximumSize (self)
  1. QSize QLayout.totalMinimumSize (self)
  1. QSize QLayout.totalSizeHint (self)

[

  1. QLayout.update (self)

](docs_qsize.html)

更新的布局parentWidget( ) 。

你通常应该不需要调用这个,因为它是自动调用在最适当的时候。

See also activate()和invalidate( ) 。

  1. QLayout.widgetEvent (self, QEvent)
  1. QLayout.__len__ (self)