May 2019
Intermediate to advanced
542 pages
13h 37m
English
QHBoxLayout and QVBoxLayout are both derived from QBoxLayout, a very basic layout engine that simply divides the parent into horizontal or vertical boxes and places widgets sequentially as they're added. QHBoxLayout is oriented horizontally, and widgets are placed from left to right as added. QVBoxLayout is oriented vertically, and widgets are placed from top to bottom as added.
Let's try QVBoxLayout on our MainWindow widget:
layout = qtw.QVBoxLayout() self.setLayout(layout)
Once the layout object exists, we can start adding our widgets to it using the addWidget() method:
layout.addWidget(label) layout.addWidget(line_edit)
As you can see, if you run the program, the widgets are added one per line. If we wanted ...
Read now
Unlock full access