from PySide2.QtWidgets import QApplication, QVBoxLayout, QLabel, QPushButton, QWidget app = QApplication([]) # Create a QVBoxLayout and a parent widget layout = QVBoxLayout() widget = QWidget() # Add a label and button to the layout label = QLabel("Hello, world!") button = QPushButton("Click me") layout.addWidget(label) layout.addWidget(button) # Set the layout on the widget and show the widget widget.setLayout(layout) widget.show() app.exec_()
from PySide2.QtWidgets import QApplication, QVBoxLayout, QLabel, QWidget app = QApplication([]) # Create a QVBoxLayout and a parent widget layout = QVBoxLayout() widget = QWidget() # Add a dynamic number of labels to the layout num_labels = 5 for i in range(num_labels): label = QLabel(f"Label {i}") layout.addWidget(label) # Set the layout on the widget and show the widget widget.setLayout(layout) widget.show() app.exec_()
from PySide2.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout, QLabel, QWidget app = QApplication([]) # Create a QVBoxLayout and a parent widget layout = QVBoxLayout() widget = QWidget() # Create two QHBoxLayouts and add two labels to each hlayout1 = QHBoxLayout() hlayout1.addWidget(QLabel("Label 1A")) hlayout1.addWidget(QLabel("Label 1B")) hlayout2 = QHBoxLayout() hlayout2.addWidget(QLabel("Label 2A")) hlayout2.addWidget(QLabel("Label 2B")) # Add the two QHBoxLayouts to the QVBoxLayout layout.addLayout(hlayout1) layout.addLayout(hlayout2) # Set the layout on the widget and show the widget widget.setLayout(layout) widget.show() app.exec_()