Adjust Spacing and Margins between Widgets in Layout

From Qt Wiki
Revision as of 14:41, 23 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search


[toc align_right="yes" depth="2"]

Adjust Spacing and Margins between Widgets in Layout

Overview

To adjust margins and spacing between "widgets":http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html use the following methods "setSpacing()":http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#spacing-prop and "setContentsMargins()":http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#setContentsMargins that are implemented in class "QLayout":http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#details.

Example

This code snippet shows how to remove spacing and margins between widgets in instance of "QVBoxLayout":http://doc.qt.io/qt-5.0/qtwidgets/qvboxlayout.html

<br />pLayout = new QVBoxLayout(this);<br />pLayout-&gt;setSpacing(0);<br />pLayout-&gt;setMargin(0);<br />pLayout-&gt;setContentsMargins(0,0,0,0);<br />pLayout-&gt;addWidget(m_pLabel, 0, Qt::AlignTop);<br />pLayout-&gt;addWidget(m_pButton, 0, Qt::AlignTop);<br />setLayout(pLayout);<br />