Adjust Spacing and Margins between Widgets in Layout

Overview

To adjust margins and spacing between widgets [doc.qt.nokia.com] use the following methods setSpacing() [doc.qt.nokia.com] and setContentsMargins() [doc.qt.nokia.com] that are implemented in class QLayout [doc.qt.nokia.com].

Example

This code snippet shows how to remove spacing and margins between widgets in instance of QVBoxLayout [doc.qt.nokia.com]

  1. pLayout = new QVBoxLayout(this);
  2. pLayout->setSpacing(0);
  3. pLayout->setMargin(0);
  4. pLayout->setContentsMargins(0,0,0,0);
  5. pLayout->addWidget(m_pLabel, 0, Qt::AlignTop);
  6. pLayout->addWidget(m_pButton, 0, Qt::AlignTop);
  7. setLayout(pLayout);

Categories: