QVBoxLayout organizes your widgets vertically in a window.

Instead of organizing all the widgets yourself (specifying the geographic location), you can let PyQt take care of it.

Every new widget you add with .addWidget(), is added vertically. Basically you get a vertical list of your widgets. Each new widget is added to the bottom of the list.

Import QVBoxLayout from PyQt5.QtWidgets.

Related Course: Create GUI Apps with Python PyQt5

Vertical layout

QVboxLayout example

The simple example below creates a QVboxLayout. Then uses the method addWidget, which adds the newly created buttons in vertical direction.

1
2
3
4
5
6
7
8
9
10
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(QPushButton('1'))
layout.addWidget(QPushButton('2'))
layout.addWidget(QPushButton('3'))
window.setLayout(layout)
window.show()
app.exec_()

This creates this app:

pyqt vertical layout

The parameter in addWidget() accepts any widget in PyQt5.QtWidgets like QPushButton and all the other available widgets.

Don’t forget to add the QVBoxLayout to the window with window.setLayout(layout).

Download Examples