QVBoxLayout Class Reference

The QVBoxLayout class lines up widgets vertically.

  1. #include <QVBoxLayout>

Inherits: QBoxLayout.

Detailed Description

The QVBoxLayout class lines up widgets vertically.

This class is used to construct vertical box layout objects. See QBoxLayout for details.

The simplest use of the class is like this:

  1.     QWidget *window = new QWidget;
  2.     QPushButton *button1 = new QPushButton("One");
  3.     QPushButton *button2 = new QPushButton("Two");
  4.     QPushButton *button3 = new QPushButton("Three");
  5.     QPushButton *button4 = new QPushButton("Four");
  6.     QPushButton *button5 = new QPushButton("Five");
  7.  
  8.     QVBoxLayout *layout = new QVBoxLayout;
  9.     layout->addWidget(button1);
  10.     layout->addWidget(button2);
  11.     layout->addWidget(button3);
  12.     layout->addWidget(button4);
  13.     layout->addWidget(button5);
  14.  
  15.     window->setLayout(layout);
  16.     window->show();

First, we create the widgets we want in the layout. Then, we create the QVBoxLayout object and add the widgets into the layout. Finally, we call QWidget::setLayout() to install the QVBoxLayout object onto the widget. At that point, the widgets in the layout are reparented to have window as their parent.

Horizontal box layout with five child widgets

Horizontal box layout with five child widgets

See also QHBoxLayout, QGridLayout, QStackedLayout, Layout Management, and Basic Layouts Example.

Public Functions

Toggle details QVBoxLayout

QVBoxLayoutQVBoxLayout () ()

Constructs a new vertical box. You must add it to another layout.

Look up this member in the source code.

Toggle details QVBoxLayout

QVBoxLayoutQVBoxLayout ( QWidget *parent ) ( QWidget *parent )

Constructs a new top-level vertical box with parent parent.

Look up this member in the source code.

Toggle details QVBoxLayout

~QVBoxLayout~QVBoxLayout () ()

Destroys this box layout.

The layout's widgets aren't destroyed.

Look up this member in the source code.

Toggle details QVBoxLayout

QVBoxLayoutQVBoxLayout ( QWidget *parent , int margin , int spacing=-1 , const char *name=0 ...) ( QWidget *parent , int margin , int spacing=-1 , const char *name=0 ) Qt3-support

Constructs a new top-level vertical box called name, with parent parent.

The margin is the number of pixels between the edge of the widget and its managed children. The spacing is the default number of pixels between neighboring children. If spacing is -1 the value of margin is used for spacing.

Look up this member in the source code.

Toggle details QVBoxLayout

QVBoxLayoutQVBoxLayout ( QLayout *parentLayout , int spacing=-1 , const char *name=0 ...) ( QLayout *parentLayout , int spacing=-1 , const char *name=0 ) Qt3-support

Constructs a new vertical box called name name and adds it to parentLayout.

The spacing is the default number of pixels between neighboring children. If spacing is -1, this QVBoxLayout will inherit its parent's spacing().

Look up this member in the source code.

Toggle details QVBoxLayout

QVBoxLayoutQVBoxLayout ( int spacing , const char *name=0 ) ( int spacing , const char *name=0 ) Qt3-support

Constructs a new vertical box called name name. You must add it to another layout.

The spacing is the default number of pixels between neighboring children. If spacing is -1, this QVBoxLayout will inherit its parent's spacing().

Look up this member in the source code.

Notes provided by the Qt Community
Informative
  • 4

Votes: 1

Coverage: Qt library 4.7, 4.8, qt 5.0

Picture of Sam Sam

Robot Herder
19 notes

Remove additional spacing

In order to remove the additional spacing while using QBoxLayout we can set the margins as

layout->setContentsMargins(QMargins(0,0,0,0));

[Revisions]