Adjust Spacing and Margins between Widgets in Layout: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Convert ExpressionEngine links)
Line 9: Line 9:
== Overview ==
== 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.
To adjust margins and spacing between [http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html widgets] use the following methods [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#spacing-prop setSpacing()] and [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#setContentsMargins setContentsMargins()] that are implemented in class [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#details QLayout].


== Example ==
== 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
This code snippet shows how to remove spacing and margins between widgets in instance of [http://doc.qt.io/qt-5.0/qtwidgets/qvboxlayout.html QVBoxLayout]


<code>
<code>

Revision as of 08:02, 4 March 2015


English | Deutsch [toc align_right="yes" depth="2"]

Adjust Spacing and Margins between Widgets in Layout

Overview

To adjust margins and spacing between widgets 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);
pLayout->setContentsMargins(0,0,0,0);
pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);
pLayout->addWidget(m_pButton, 0, Qt::AlignTop);
setLayout(pLayout);