from PySide2.QtWidgets import QWidget, QHBoxLayout, QPushButton, QLabel class MainWindow(QWidget): def __init__(self): super().__init__() # Create a QHBoxLayout and add widgets to it hbox = QHBoxLayout() hbox.addWidget(QPushButton("Button 1")) hbox.addWidget(QLabel("Label 1")) hbox.addWidget(QPushButton("Button 2")) hbox.addWidget(QLabel("Label 2")) self.setLayout(hbox)
from PySide2.QtWidgets import QWidget, QHBoxLayout, QPushButton class MainWindow(QWidget): def __init__(self): super().__init__() # Create a QHBoxLayout and set margins and spacing hbox = QHBoxLayout() hbox.setContentsMargins(50, 50, 50, 50) hbox.setSpacing(20) # Add widgets to the QHBoxLayout hbox.addWidget(QPushButton("Button 1")) hbox.addWidget(QPushButton("Button 2")) self.setLayout(hbox)This creates a horizontal layout and sets margins and spacing for the layout. Two buttons are added to the layout. As stated earlier, the PySide2.QtWidgets package library includes the QHBoxLayout class.