QHBoxLayout Class

QHBoxLayout 类水平排列部件。更多

Header: #include <QHBoxLayout>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QBoxLayout

公共函数

QHBoxLayout()
QHBoxLayout(QWidget *parent)
virtual ~QHBoxLayout()

详细说明

该类用于构建水平方框布局对象。详见QBoxLayout

该类最简单的用法是这样的:

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

    QHBoxLayout *layout = new QHBoxLayout(window);
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);

    window->show();

首先,我们创建要添加到布局中的部件。然后,创建 QHBoxLayout 对象,并在构造函数中通过window 将其设置为父级;接着,将部件添加到布局中。window 将是添加到布局中的部件的父级。

如果不在构造函数中传递父级window ,可以在以后使用QWidget::setLayout() 将 QHBoxLayout 对象安装到window 上。此时,布局中的部件将被重新父对象化,以window 作为父对象。

带五个子部件的水平框布局

另请参阅 QVBoxLayout,QGridLayout,QStackedLayout,布局管理基本布局示例

成员函数文档

QHBoxLayout::QHBoxLayout()

新建一个水平方框。您必须将其添加到另一个布局中。

[explicit] QHBoxLayout::QHBoxLayout(QWidget *parent)

新建一个顶层水平方框,父级为parent

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

另请参阅 QWidget::setLayout()。

[virtual noexcept] QHBoxLayout::~QHBoxLayout()

销毁此盒式布局。

布局的部件不会被销毁。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.