Adjust Spacing and Margins between Widgets in Layout: Difference between revisions
Jump to navigation
Jump to search
m (Layout) |
|||
Line 13: | Line 13: | ||
pLayout->setMargin(0); | pLayout->setMargin(0); | ||
pLayout->setContentsMargins(0,0,0,0); | |||
// This is redundant with setMargin, | |||
// which is deprecated | |||
pLayout->setContentsMargins(0,0,0,0); | |||
pLayout->addWidget(m_pLabel, 0, Qt::AlignTop); | pLayout->addWidget(m_pLabel, 0, Qt::AlignTop); |
Revision as of 21:56, 21 August 2016
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->setMargin(0);
// This is redundant with setMargin,
// which is deprecated
pLayout->setContentsMargins(0,0,0,0);
pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);
pLayout->addWidget(m_pButton, 0, Qt::AlignTop);
setLayout(pLayout);