How to align children in a QHBoxLayout Left, Center and Right

Depending on what you want, you could also define the alignment while adding the widgets like so:

auto h = new QHBoxLayout();
h->addWidget(leftLabel, 0, Qt::AlignLeft);
h->addWidget(centerLabel, 0, Qt::AlignCenter);
h->addLayout(rightLabel, 0, Qt::AlignRight);

See here for more Information


Just add spacers between "Left", "Center" and "Right":

QHBoxLayout *h = new QHBoxLayout(&parentWidget);
h->addWidget(leftLabel);
h->addStretch()
h->addWidget(centerLabel);
h->addStretch()
h->addLayout(rightLabel);

Might be helpful to practice in Qt Designer.

Tags:

C++

Layout

Qt