In Qt Designer I can set the margin of a VBox or HBox using the properties layout*Margin.
How can I do that in pyqt?
In PyQt, layout managers are classes that provide the required functionality to automatically manage the size, position, and resizing behavior of the widgets in the layout. With layout managers, you can automatically arrange child widgets within any parent, or container, widget.
First, we create the widgets we want in the layout. Then, we create the QHBoxLayout object and add the widgets into the layout. Finally, we call setLayout() to install the QHBoxLayout object onto the widget. At that point, the widgets in the layout are reparented to have window as their parent.
PyQt5 Tutorial — Getting started with PyQt5 In Qt (and most User Interfaces) 'widget' is the name given to a component of the UI that the user can interact with. User interfaces are made up of multiple widgets, arranged within the window.
You can use QLayout.setContentsMargins:
# layout is a defined VBox or HBox
layout.setContentsMargins(left, top, right, bottom)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With