Adjust Spacing and Margins between Widgets in Layout: Difference between revisions
Jump to navigation
Jump to search
(Style) |
m (add: Note: QLayout::setMargins was removed in qt6) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
== Overview == | {{LangSwitch}} | ||
To adjust margins and spacing between {{DocLink|QWidget}}s use the following methods {{ | ==Overview== | ||
To adjust margins and spacing between {{DocLink|QWidget}}s use the following methods {{DocLink|QLayout|spacing-prop|setSpacing}} and {{DocLink|QLayout|contentsMargins|setContentsMargins}} that are implemented in class {{DocLink|QLayout}}. | |||
== Example == | ==Example== | ||
This code snippet shows how to remove spacing and margins between widgets in instance of {{DocLink|QVBoxLayout}}. | This code snippet shows how to remove spacing and margins between widgets in instance of {{DocLink|QVBoxLayout}}. | ||
< | <pre> | ||
pLayout = new QVBoxLayout(this); | pLayout = new QVBoxLayout(this); | ||
pLayout->setSpacing(0); | pLayout->setSpacing(0); | ||
pLayout->setContentsMargins(0, 0, 0, 0); | |||
pLayout->setContentsMargins(0,0,0,0); | |||
pLayout->addWidget(m_pLabel, 0, Qt::AlignTop); | pLayout->addWidget(m_pLabel, 0, Qt::AlignTop); | ||
Line 18: | Line 17: | ||
setLayout(pLayout); | setLayout(pLayout); | ||
</code> | </pre> | ||
Note: <code>QLayout::setMargins</code> was removed in qt6 |
Latest revision as of 17:09, 27 January 2023
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