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:
[[Category:HowTo]]<br />[[Category:snippets]]
[[Category:HowTo]]
[[Category:snippets]]


'''English''' | [[Adjust_Spacing_and_Margins_between_Widgets_in_Layout_German|Deutsch]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]
'''English''' | [[Adjust_Spacing_and_Margins_between_Widgets_in_Layout_German|Deutsch]]
[toc align_right="yes" depth="2"]


= Adjust Spacing and Margins between Widgets in Layout =
= Adjust Spacing and Margins between Widgets in Layout =
Line 7: Line 9:
== Overview ==
== Overview ==


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.
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 ==
== Example ==


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
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


<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>
<code>
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);
</code>

Revision as of 09:05, 25 February 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":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

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);