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

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Adjust Spacing and Margins between Widgets in Layout=
[[Category:HowTo]]<br />[[Category:snippets]]


==Overview==
[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]


To adjust margins and spacing between [http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html widgets] ''[qt.io]'' use the following methods [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#spacing-prop setSpacing()] ''[qt.io]'' and [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#setContentsMargins setContentsMargins()] ''[qt.io]'' that are implemented in class [http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#details QLayout] ''[qt.io]''.
= Adjust Spacing and Margins between Widgets in Layout =


==Example==
== Overview ==


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] ''[qt.io]''
To adjust margins and spacing between &quot;widgets&amp;quot;:http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html use the following methods &quot;setSpacing()&quot;:http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#spacing-prop and &quot;setContentsMargins()&quot;:http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#setContentsMargins that are implemented in class &quot;QLayout&amp;quot;:http://doc.qt.io/qt-5.0/qtwidgets/qlayout.html#details.


===Categories:===
== Example ==


* [[:Category:HowTo|HowTo]]
This code snippet shows how to remove spacing and margins between widgets in instance of &quot;QVBoxLayout&amp;quot;:http://doc.qt.io/qt-5.0/qtwidgets/qvboxlayout.html
* [[:Category:snippets|snippets]]
 
<code><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 /></code>

Revision as of 14:41, 23 February 2015


[toc align_right="yes&quot; depth="2&quot;]

Adjust Spacing and Margins between Widgets in Layout

Overview

To adjust margins and spacing between "widgets&quot;: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&quot;: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&quot;: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 />