Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Adjust Spacing and Margins between Widgets in Layout: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:HowTo]]<br />[[Category:snippets]] | |||
== | [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 | |||
<code><br />pLayout = new QVBoxLayout(this);<br />pLayout->setSpacing(0);<br />pLayout->setMargin(0);<br />pLayout->setContentsMargins(0,0,0,0);<br />pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);<br />pLayout->addWidget(m_pButton, 0, Qt::AlignTop);<br />setLayout(pLayout);<br /></code> |
Revision as of 14:41, 23 February 2015
[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->setSpacing(0);<br />pLayout->setMargin(0);<br />pLayout->setContentsMargins(0,0,0,0);<br />pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);<br />pLayout->addWidget(m_pButton, 0, Qt::AlignTop);<br />setLayout(pLayout);<br />