import PySide2.QtWidgets as QtWidgets layout = QtWidgets.QVBoxLayout() layout.setSpacing(10) # Set a spacing of 10 pixels between widgets in the layout
import PySide2.QtWidgets as QtWidgets app = QtWidgets.QApplication([]) window = QtWidgets.QMainWindow() layout = QtWidgets.QVBoxLayout() layout.setSpacing(20) button1 = QtWidgets.QPushButton("Button 1") button2 = QtWidgets.QPushButton("Button 2") button3 = QtWidgets.QPushButton("Button 3") layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) widget = QtWidgets.QWidget() widget.setLayout(layout) window.setCentralWidget(widget) window.show() app.exec_()This code creates a QMainWindow and adds a QVBoxLayout to its central widget. Buttons are added to the layout with a spacing of 20 pixels between them. This demonstrates how setSpacing can be used to create a visually appealing layout. Package library: PySide2.