Nesta página

QHBoxLayout Class

A classe QHBoxLayout alinha widgets horizontalmente. Mais...

Cabeçalho: #include <QHBoxLayout>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
Herdado de: QBoxLayout

Funções públicas

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

Descrição detalhada

Esta classe é usada para construir objetos de layout em caixa horizontal. Consulte QBoxLayout para obter detalhes.

A maneira mais simples de usar a classe é assim:

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

Primeiro, criamos os widgets que queremos adicionar ao layout. Em seguida, criamos o objeto QHBoxLayout, definindo window como pai ao passá-lo no construtor; depois, adicionamos os widgets ao layout. window será o pai dos widgets adicionados ao layout.

Se você não passar um pai window para o construtor, poderá, posteriormente, usar QWidget::setLayout() para instalar o objeto QHBoxLayout em window. Nesse momento, os widgets no layout terão seu pai alterado para window.

Cinco botões dispostos horizontalmente

Consulte também ` QVBoxLayout` , ` QGridLayout`, ` QStackedLayout`, Gerenciamento de layout e Exemplo de layouts básicos.

Documentação das funções de membro

QHBoxLayout::QHBoxLayout()

Cria uma nova caixa horizontal. É necessário adicioná-la a outro layout.

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

Cria uma nova caixa horizontal de nível superior com o pai parent.

O layout é definido diretamente como o layout de nível superior para ` parent`. Só pode haver um layout de nível superior para um widget. Ele é retornado pela função ` QWidget::layout()`.

Veja também ` QWidget::setLayout()`.

[virtual noexcept] QHBoxLayout::~QHBoxLayout()

Destrói este layout de caixa.

Os widgets do layout não são destruídos.

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