Skip to content

QHBoxLayout


The QHBoxLayout class lines up widgets horizontally. If the widgets do not fit in the window, the layout will automatically wrap or resize them. For a vertical layout, use QVBoxLayout.


Methods


Examples


layout = QtWidgets.QHBoxLayout()
layout.addWidget(QPushButton("Button 1"))
layout.addWidget(QPushButton("Button 2"))
In the above example, a horizontal layout is created, and two buttons are added to it using the addWidget method from the parent QLayout parent class. The buttons will be aligned horizontally.


h_layout = QtWidgets.QHBoxLayout()
v_layout = QtWidgets.QVBoxLayout()
h_layout.addLayout(v_layout)
In the above example, a horizontal layout is created, added to a central widget, and a vertical layout is added to it.



addLayout(layout)

Adds a layout to the horizontal box layout. The layout will be added to the right of the existing layouts.

Parameters:

Name Type Description Default
layout QLayout

the layout to add.

required