QHBoxLayout Class

QHBoxLayout Class

QHBoxLayout Class

QHBoxLayout 类水平排列部件。更多

Header: #include

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.

相关推荐

魔兽世界卡加斯怎么去
365bet网投官网

魔兽世界卡加斯怎么去

📅 07-19 👁️ 9572
容园美RONYME
365bet网投官网

容园美RONYME

📅 07-08 👁️ 2532
电警棍能有多少伏?电警棍一般什么价格,哪里可以合法买到电警棍?
内蒙古自治区第七次全国人口普查公报(第一号)
365bet网投官网

内蒙古自治区第七次全国人口普查公报(第一号)

📅 07-02 👁️ 8365
汉字“毑乸姬姫”,你会读吗?什么意思你知道吗?很多人不认识
魔兽世界永恒岛稀有怪刷新间隔多久 魔兽永恒岛成就任务攻略