Skip To Main

Pyqt6 — Widgets

PyQt6's extensive widget library allows building professional, cross-platform desktop applications with native look and feel. The combination of layout managers, signals/slots, and style sheets gives you complete control over both behavior and appearance.

from PyQt6.QtWidgets import * from PyQt6.QtCore import Qt layout = QHBoxLayout() layout.addWidget(QLabel("Name:")) layout.addWidget(QLineEdit()) layout.setStretchFactor(layout.itemAt(1).widget(), 1) # Text field expands Every widget emits signals (events) that connect to other widget methods or custom functions: pyqt6 widgets

def show_text(self): text = self.line.text() if text: self.label.setText(f"You typed: text") else: self.label.setText("Nothing typed!") pyqt6 widgets

def update_combo_label(self, text): self.combo_label.setText(f"Selected: text") app = QApplication(sys.argv) window = DemoWindow() window.show() sys.exit(app.exec()) | Use Case | Recommended Widget | |--------------|------------------------| | Simple text input | QLineEdit | | Multi-line text | QTextEdit | | Numeric bounded input | QSpinBox | | Yes/No option | QCheckBox | | Exclusive choice (2-5 options) | QRadioButton + QButtonGroup | | Exclusive choice (many options) | QComboBox | | List of strings | QListWidget | | Table of editable data | QTableWidget | | Hierarchical data | QTreeWidget | | Progress indication | QProgressBar | | Form layout | QFormLayout + QLineEdit / QComboBox | | Image display | QLabel with QPixmap | pyqt6 widgets