Adjust Spacing and Margins between Widgets in Layout

From Qt Wiki
Revision as of 17:09, 27 January 2023 by Milahu (talk | contribs) (add: Note: QLayout::setMargins was removed in qt6)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Overview

To adjust margins and spacing between QWidgets use the following methods setSpacing and setContentsMargins that are implemented in class QLayout.

Example

This code snippet shows how to remove spacing and margins between widgets in instance of QVBoxLayout.

pLayout = new QVBoxLayout(this);

pLayout->setSpacing(0);
pLayout->setContentsMargins(0, 0, 0, 0);

pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);
pLayout->addWidget(m_pButton, 0, Qt::AlignTop);

setLayout(pLayout);

Note:

QLayout::setMargins

was removed in qt6