In questa pagina

QHBoxLayout Class

La classe QHBoxLayout allinea i widget in orizzontale. Per saperne di più...

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

Funzioni pubbliche

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

Descrizione dettagliata

Questa classe viene utilizzata per costruire oggetti di layout a riquadri orizzontali. Per ulteriori dettagli, consultare QBoxLayout.

L'uso più semplice della classe è il seguente:

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

Per prima cosa, creiamo i widget che vogliamo aggiungere al layout. Poi, creiamo l'oggetto QHBoxLayout, impostando window come genitore passandolo al costruttore; successivamente aggiungiamo i widget al layout. window sarà il genitore dei widget aggiunti al layout.

Se non si passa un genitore window al costruttore, è possibile in un secondo momento utilizzare QWidget::setLayout() per inserire l'oggetto QHBoxLayout in window. A quel punto, i widget nel layout vengono riassegnati in modo da avere window come genitore.

Cinque pulsanti disposti in orizzontale

Vedi anche QVBoxLayout, QGridLayout, QStackedLayout, Gestione dei layout ed Esempio di layout di base.

Documentazione sulle funzioni membro

QHBoxLayout::QHBoxLayout()

Crea un nuovo riquadro orizzontale. È necessario aggiungerlo a un altro layout.

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

Crea un nuovo riquadro orizzontale di primo livello con il genitore parent.

Il layout viene impostato direttamente come layout di primo livello per parent. Per un widget può esserci un solo layout di primo livello. Viene restituito dalla funzione QWidget::layout().

Vedi anche QWidget::setLayout().

[virtual noexcept] QHBoxLayout::~QHBoxLayout()

Elimina questo layout della casella.

I widget del layout non vengono eliminati.

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