En esta página

QHBoxLayout Class

La clase QHBoxLayout alinea los widgets horizontalmente. Más...

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

Funciones Públicas

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

Descripción Detallada

Esta clase se utiliza para construir objetos de diseño de caja horizontal. Véase QBoxLayout para más detalles.

El uso más sencillo de esta clase es el siguiente:

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();

Primero, creamos los widgets que queremos añadir al layout. Después, creamos el objeto QHBoxLayout, estableciendo window como padre pasándolo en el constructor; a continuación añadimos los widgets al layout. window será el padre de los widgets que se añadan al layout.

Si no pasas un padre window al constructor, puedes usar más tarde QWidget::setLayout() para instalar el objeto QHBoxLayout en window. En ese momento, los widgets del layout son reparentados para tener window como padre.

Cinco botones en disposición horizontal

Ver también QVBoxLayout, QGridLayout, QStackedLayout, Gestión de Layouts, y Ejemplo de Layouts Básicos.

Documentación de las funciones miembro

QHBoxLayout::QHBoxLayout()

Construye una nueva caja horizontal. Debe añadirla a otro diseño.

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

Construye una nueva caja horizontal de nivel superior con el padre parent.

El diseño se establece directamente como el diseño de nivel superior para parent. Sólo puede haber un diseño de nivel superior para un widget. Es devuelto por QWidget::layout().

Véase también QWidget::setLayout().

[virtual noexcept] QHBoxLayout::~QHBoxLayout()

Destruye este diseño de caja.

Los widgets del diseño no se destruyen.

© 2026 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.