内容表

上一话题

QApplication

下一话题

QButtonGroup

QBoxLayout

QBoxLayout class lines up child widgets horizontally or vertically. 更多

Inheritance diagram of PySide2.QtWidgets.QBoxLayout

继承者: QHBoxLayout , QVBoxLayout

概要

函数

详细描述

QBoxLayout takes the space it gets (from its parent layout or from the parentWidget() ), divides it up into a row of boxes, and makes each managed widget fill one box.

../../_images/qhboxlayout-with-5-children.png

QBoxLayout ‘s orientation is Horizontal 框按合适尺寸排成一行。每个 Widget (或其它框) 将至少获得其最小尺寸和最多获得其最大尺寸。任何多余空间根据拉伸因子共享 (下文有关这更多)。

../../_images/qvboxlayout-with-5-children.png

QBoxLayout ‘s orientation is Vertical ,框被放置在列中,再采用合适尺寸。

The easiest way to create a QBoxLayout is to use one of the convenience classes, e.g. QHBoxLayout (for Horizontal 框) 或 QVBoxLayout (for Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight , RightToLeft , TopToBottom ,或 BottomToTop .

QBoxLayout is not the top-level layout (i.e. it is not managing all of the widget’s area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout-> addLayout() .

Once you have done this, you can add boxes to the QBoxLayout using one of four functions:

  • addWidget() to add a widget to the QBoxLayout and set the widget’s stretch factor. (The stretch factor is along the row of boxes.)

  • addSpacing() to create an empty box; this is one of the functions you use to create nice and spacious dialogs. See below for ways to set margins.

  • addStretch() to create an empty, stretchable box.

  • addLayout() to add a box containing another QLayout to the row and set that layout’s stretch factor.

使用 insertWidget() , insertSpacing() , insertStretch() or insertLayout() to insert a box at a specified position in the layout.

QBoxLayout also includes two margin widths:

  • setContentsMargins() sets the width of the outer border on each side of the widget. This is the width of the reserved space along each of the QBoxLayout ‘s four sides.

  • setSpacing() sets the width between neighboring boxes. (You can use addSpacing() to get more space at a particular spot.)

边距默认由样式提供。大多数 Qt 样式指定的默认边距对于 Widget 为 9,对于窗口为 11。间距默认与顶层布局边距宽度相同,或与父布局相同。

要从布局移除 Widget,调用 removeWidget() 。调用 hide() on a widget also effectively removes the widget from the layout until show() 被调用。

几乎总是想要使用 QVBoxLayout and QHBoxLayout 而不是 QBoxLayout because of their convenient constructors.

class QBoxLayout ( arg__1 [ , parent=None ] )
param parent

QWidget

param arg__1

Direction

构造新 QBoxLayout with direction dir 和父级 Widget parent .

另请参阅

direction()

PySide2.QtWidgets.QBoxLayout. Direction

此类型用于确定框布局的方向。

常量

描述

QBoxLayout.LeftToRight

水平从左到右。

QBoxLayout.RightToLeft

水平从右到左。

QBoxLayout.TopToBottom

垂直从上到下。

QBoxLayout.BottomToTop

垂直从下到上。

PySide2.QtWidgets.QBoxLayout. addLayout ( layout [ , stretch=0 ] )
参数

添加 layout 到方框末尾,采用连续拉伸因子 stretch .

另请参阅

insertLayout() addItem() addWidget()

PySide2.QtWidgets.QBoxLayout. addSpacerItem ( spacerItem )
参数

spacerItem QSpacerItem

添加 spacerItem 到此方框布局的末尾。

PySide2.QtWidgets.QBoxLayout. addSpacing ( size )
参数

size int

添加不可拉伸空间 ( QSpacerItem ) 采用尺寸 size 到此方框布局的末尾。 QBoxLayout 提供默认边距和间距。此函数添加额外空间。

另请参阅

insertSpacing() addItem() QSpacerItem

PySide2.QtWidgets.QBoxLayout. addStretch ( [ stretch=0 ] )
参数

stretch int

添加可拉伸空间 ( QSpacerItem ) with zero minimum size and stretch factor stretch 到此方框布局的末尾。

另请参阅

insertStretch() addItem() QSpacerItem

PySide2.QtWidgets.QBoxLayout. addStrut ( arg__1 )
参数

arg__1 int

Limits the perpendicular dimension of the box (e.g. height if the box is LeftToRight ) to a minimum of size . Other constraints may increase the limit.

另请参阅

addItem()

PySide2.QtWidgets.QBoxLayout. addWidget ( arg__1 [ , stretch=0 [ , alignment=Qt.Alignment() ] ] )
参数
  • arg__1 QWidget

  • stretch int

  • alignment Alignment

添加 widget 到此框布局的末尾,采用拉伸因子 stretch 和对齐 alignment .

拉伸因子仅应用于 direction QBoxLayout ,且相对于其它方框和 Widget 在此 QBoxLayout 。具有更高拉伸因子的 Widget 和方框增长更多。

若拉伸因子为 0 且什么都没有除非 QBoxLayout 拥有大于 0 的拉伸因子,空间分布将根据 QWidget :sizePolicy() of each widget that’s involved.

对齐方式的指定通过 alignment 。默认对齐为 0,意味着 Widget 填充整个单元格。

PySide2.QtWidgets.QBoxLayout. direction ( )
返回类型

Direction

返回框的方向。 addWidget() and addSpacing() work in this direction; the stretch stretches in this direction.

PySide2.QtWidgets.QBoxLayout. insertItem ( index , arg__2 )
参数

插入 item 到此框布局在位置 index 。若 index 为负,项被添加在末尾。

PySide2.QtWidgets.QBoxLayout. insertLayout ( index , layout [ , stretch=0 ] )
参数
  • index int

  • layout QLayout

  • stretch int

插入 layout 在位置 index ,采用拉伸因子 stretch 。若 index 为负,布局被添加在末尾。

layout 变为框布局的子级。

PySide2.QtWidgets.QBoxLayout. insertSpacerItem ( index , spacerItem )
参数

插入 spacerItem 在位置 index , with zero minimum size and stretch factor. If index 为负,空间被添加在末尾。

PySide2.QtWidgets.QBoxLayout. insertSpacing ( index , size )
参数
  • index int

  • size int

插入不可拉伸空间 ( QSpacerItem ) 在位置 index ,采用尺寸 size 。若 index 为负,空间被添加在末尾。

框布局具有默认的边距和间距。此函数添加额外空间。

PySide2.QtWidgets.QBoxLayout. insertStretch ( index [ , stretch=0 ] )
参数
  • index int

  • stretch int

插入可拉伸空间 ( QSpacerItem ) 在位置 index ,采用 0 最小尺寸和拉伸因子 stretch 。若 index 为负,空间被添加在末尾。

PySide2.QtWidgets.QBoxLayout. insertWidget ( index , widget [ , stretch=0 [ , alignment=Qt.Alignment() ] ] )
参数
  • index int

  • widget QWidget

  • stretch int

  • alignment Alignment

插入 widget 在位置 index ,采用拉伸因子 stretch 和对齐 alignment 。若 index 为负,Widget 被添加到末尾。

拉伸因子仅应用于 direction QBoxLayout ,且相对于其它方框和 Widget 在此 QBoxLayout 。具有更高拉伸因子的 Widget 和方框增长更多。

若拉伸因子为 0 且什么都没有除非 QBoxLayout 拥有大于 0 的拉伸因子,空间分布将根据 QWidget :sizePolicy() of each widget that’s involved.

对齐方式的指定通过 alignment 。默认对齐为 0,意味着 Widget 填充整个单元格。

PySide2.QtWidgets.QBoxLayout. setDirection ( arg__1 )
参数

arg__1 Direction

将此布局的方向设为 direction .

另请参阅

direction()

PySide2.QtWidgets.QBoxLayout. setStretch ( index , stretch )
参数
  • index int

  • stretch int

设置拉伸因子在位置 index . to stretch .

另请参阅

stretch()

PySide2.QtWidgets.QBoxLayout. setStretchFactor ( l , stretch )
参数
返回类型

bool

这是重载函数。

设置拉伸因子为布局 layout to stretch 并返回 true if layout 在此布局中被找到 (不包括子级布局);否则返回 false .

PySide2.QtWidgets.QBoxLayout. setStretchFactor ( w , stretch )
参数
返回类型

bool

设置拉伸因子为 widget to stretch and returns true if widget 在此布局中被找到 (不包括子级布局);否则返回 false .

另请参阅

setAlignment()

PySide2.QtWidgets.QBoxLayout. stretch ( index )
参数

index int

返回类型

int

返回拉伸因子在位置 index .

另请参阅

setStretch()