PySide6.QtWidgets.QHBoxLayout

class QHBoxLayout

QHBoxLayout 类将小部件水平排列。更多

PySide6.QtWidgets.QHBoxLayout 的继承图

概要

方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

警告

本节包含从C++自动翻译到Python的代码片段,可能包含错误。

此类用于构造水平框布局对象。详情请参见QBoxLayout

类的最简单用法如下:

window = QWidget()
button1 = QPushButton("One")
button2 = QPushButton("Two")
button3 = QPushButton("Three")
button4 = QPushButton("Four")
button5 = QPushButton("Five")

layout = QHBoxLayout(window)
layout.addWidget(button1)
layout.addWidget(button2)
layout.addWidget(button3)
layout.addWidget(button4)
layout.addWidget(button5)
window.show()

首先,我们创建要添加到布局中的小部件。然后,我们创建QHBoxLayout对象,通过在构造函数中传递window来将其设置为父对象;接下来我们将小部件添加到布局中。window将成为添加到布局中的小部件的父对象。

如果你没有传递一个父级window给构造函数,你可以在稍后使用setLayout()QHBoxLayout对象安装到window上。此时,布局中的小部件将被重新设置为以window作为它们的父级。

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

另请参阅

QVBoxLayout QGridLayout QStackedLayout 布局管理 基本布局示例

__init__()

构造一个新的水平框。你必须将其添加到另一个布局中。

__init__(parent)
Parameters:

父级QWidget

构建一个新的顶级水平框,其父级为 parent

布局直接设置为parent的顶级布局。一个部件只能有一个顶级布局。它由layout()返回。

另请参阅

setLayout()