PY

pyqt6-patterns

PyQt6 patterns for stable desktop apps. Prevents UI freezes with background threading and signal-based communication.

Install

mkdir -p .claude/skills/pyqt6-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10036" && unzip -o skill.zip -d .claude/skills/pyqt6-patterns && rm skill.zip

Installs to .claude/skills/pyqt6-patterns

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Best practices and patterns for building robust PyQt6 desktop applications
74 charsno explicit “when” trigger
Intermediate

Key capabilities

  • Separate UI from core logic
  • Implement background tasks using QThread
  • Manage signal-slot communication
  • Apply responsive UI layouts
  • Handle thread-safe error reporting

How it works

It enforces an architecture where heavy tasks are offloaded to QThread worker classes, communicating results back to the main UI thread via signals.

Inputs & outputs

You give it
PyQt6 application requirements
You get back
Architected PyQt6 code structure

When to use pyqt6-patterns

  • Handling long-running background tasks
  • Structuring PyQt6 windows
  • Implementing signal-slot communication

About this skill

PyQt6 Patterns Skill

Guide for building Desktop applications with PyQt6, focusing on architecture, threading, and user experience.

🏗️ Architecture Pattern

Use a model that separates UI and Logic:

  1. MainWindow: Manages UI, Layout, Signals.
  2. Worker Thread (QThread): Handles long-running tasks (IO, Network, Heavy computation).
  3. Core Logic: Pure Python functions, independent of GUI.

Example Structure main.py

# Imports
from PyQt6.QtWidgets import ...
from PyQt6.QtCore import QThread, pyqtSignal

# 1. Background Thread Class
class WorkerThread(QThread):
    progress = pyqtSignal(int, str)
    finished = pyqtSignal(object)
    error = pyqtSignal(str)

    def run(self):
        try:
            # Heavy task here
            pass
        except Exception as e:
            self.error.emit(str(e))

# 2. Main Window Class
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def start_task(self):
        self.thread = WorkerThread(...)
        self.thread.progress.connect(self.on_progress)
        self.thread.finished.connect(self.on_finished)
        self.thread.start()

🧵 Threading (Critical)

Inviolable Rule: NEVER run heavy tasks on the Main Thread.

Why?

  • Blocks Main Thread -> UI freezes (Not Responding).
  • On macOS: Causes "Beachball of death".

Standard Pattern

Use QThread:

  1. Create a class inheriting from QThread.
  2. Define Signals (pyqtSignal) to communicate back to Main Thread.
  3. Override run() method.
  4. Initialize and keep reference to thread (self.thread) in MainWindow.
  5. Connect signals and call start().

🎨 UI & Layouts

Layout Hierarchy

Always use Layouts for responsive UI:

QMainWindow
└── CentralWidget (QWidget)
    └── QVBoxLayout
        ├── QGroupBox ("Input")
        │   └── QFormLayout
        ├── QGroupBox ("Settings")
        │   └── QVBoxLayout
        └── QGroupBox ("Actions")
            └── QHBoxLayout

Styles

Use Fusion style for a clean cross-platform look:

app = QApplication(sys.argv)
app.setStyle("Fusion")

⚠️ Error Handling

Pattern: Try-Except-Signal

In Worker Thread, always use try-except and emit error signal:

def run(self):
    try:
        # Dangerous code
        do_work()
    except Exception as e:
        self.error.emit(str(e)) # Send error to UI
    ```

In UI, listen for signal and show MessageBox:
```python
def on_error(self, message):
    self.btn_start.setEnabled(True) # Re-enable UI
    QMessageBox.critical(self, "Error", message)

📝 Widget Common Patterns

File Browsing

path = QFileDialog.getExistingDirectory(self, "Select Folder")
if path:
    self.input_dir = path
    self.label.setText(path)

Progress Bar

  • Unknown duration: progressBar.setRange(0, 0)
  • Known duration: emit(percent) from thread -> progressBar.setValue(percent)

Logs Display

Use QTextEdit readonly to display realtime logs:

self.log_text = QTextEdit()
self.log_text.setReadOnly(True)
# Append log signal
self.log_text.append(message)

✅ Best Practices Checklist

  • Always using QThread for tasks taking > 0.1s
  • Handling Exceptions in thread and reporting to UI
  • Disabling Start button while running
  • Clear code structure (Imports -> Thread -> Window -> Main)
  • Using Type Hinting for readable code

🤖 Agentic Protocol

Skill Metadata

  • Version: 1.0.0
  • Last Updated: 2026-01-27

1. Activation Log

When activating this skill (generating code), print: "🎯 [SKILL ACTIVATED] pyqt6-patterns v1.0.0" "📋 Parameters:" " - Component: [MainWindow|WorkerThread|Dialog]" " - Pattern Applied: [Threading|Layout|Signal-Slot]"

2. User Confirmation

Before applying major architectural changes: "I'm implementing the [Pattern Name] pattern for [Component]. This will structure the code as [Description]. Proceed?"

3. Completion Log

  • Success: "✅ [pyqt6-patterns] Implementation ready. Validated imports and signals."
  • Warning: "⚠️ [pyqt6-patterns] Note: Ensure [dependency] is installed."

When not to use it

  • Running heavy tasks on the main thread

Limitations

  • Heavy tasks must not run on the main thread

How it compares

It provides a structured pattern for threading and UI separation instead of writing monolithic, blocking main-thread code.

Compared to similar skills

pyqt6-patterns side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
pyqt6-patterns (this skill)06moNo flagsIntermediate
tui04moNo flagsIntermediate
textual1439moReviewIntermediate
streamlit869moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

tui

re-cinq

Expert terminal user interface development including interactive console applications, cross-platform TUI libraries, and responsive terminal layouts

00

textual

KyleKing

Expert guidance for building TUI (Text User Interface) applications with the Textual framework. Invoke when user asks about Textual development, TUI apps, widgets, screens, CSS styling, reactive programming, or testing Textual applications.

143346

streamlit

sverzijl

When working with Streamlit web apps, data dashboards, ML/AI app UIs, interactive Python visualizations, or building data science applications with Python

86239

telegram-bot-builder

davila7

Expert in building Telegram bots that solve real problems - from simple automation to complex AI-powered bots. Covers bot architecture, the Telegram Bot API, user experience, monetization strategies, and scaling bots to thousands of users. Use when: telegram bot, bot api, telegram automation, chat bot telegram, tg bot.

106130

codex-cli-bridge

alirezarezvani

Bridge between Claude Code and OpenAI Codex CLI - generates AGENTS.md from CLAUDE.md, provides Codex CLI execution helpers, and enables seamless interoperability between both tools

9180

code-to-music

Cam10001110101

Tools, patterns, and utilities for creating music with code. Output as a .mp3 file with realistic instrument sounds. Write custom compositions to bring creativity to life through music. This skill should be used whenever the user asks for music to be created. Never use this skill for replicating songs, beats, riffs, or other sensitive works. The skill is not suitable for vocal/lyrical music, audio mixing/mastering (reverb, EQ, compression), real-time MIDI playback, or professional studio recording quality.

17164

Search skills

Search the agent skills registry