شعار Pyqt

Pyqt

مؤسسة
CodeAtCode
pyqt

Use when building cross-platform desktop apps with PyQt6 or PySide6 - hub for installation, project structure, signals and slots basics, and pointers to widgets, styling, dialogs, threading, and testing sub-skills

نظرة عامة

الناشرCodeAtCode
المستودعoss-ai-skills
اسم المهارةpyqt
النجوم
30
التفريعات
3
الملفات المرفقة
18
الترخيصGPL-3.0
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 18

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها CodeAtCode على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Pyqt في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى الإضافات → المهارات.
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/CodeAtCode/oss-ai-skills/tree/master/frameworks/pyqt
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات → المهارات → إضافة مهارة → من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/CodeAtCode/oss-ai-skills.git /tmp/oss-ai-skills
mkdir -p .claude/skills
cp -r /tmp/oss-ai-skills/frameworks/pyqt .claude/skills/pyqt
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Pyqt في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج Pyqt تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Pyqt بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تترتب أي تكلفة على المهارة غير المستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Objective: Use this skill to prevent architectural decay and cross-thread UI crashes by enforcing MVC/MVVM separation, signal-based communication, and proper thread affinity rules.

PyQt/PySide Development

PyQt and PySide are Python bindings for the Qt application framework for building cross-platform desktop applications.

Sub-Skills

For detailed information, see the specialized sub-skills:

SkillDescriptionPath
pyqt-coreSignals, slots, timers, settings, file I/Ocore/SKILL.md
pyqt-widgetsAll widgets and layoutswidgets/SKILL.md
pyqt-threadingQThread, thread pools, concurrencythreading/SKILL.md
pyqt-dialogsStandard and custom dialogsdialogs/SKILL.md
pyqt-testingpytest-qt testing patternstesting/SKILL.md
pyqt-stylingQSS styling and themesstyling/SKILL.md
pyqt-multimediaAudio, video, camera, recordingmultimedia/SKILL.md

Architecture Decision: MVC vs MVVM in Qt

Qt supports multiple architectural patterns. Choose based on your data-display complexity.

MVC (Model-View-Controller)

When to use: Simple data display with inline editing, standard item views.

  • Model: QAbstractItemModel subclass owns the data
  • View: QTableView, QTreeView, QListView displays data
  • Controller: Built into the view (header clicks, selection handling)
  • Validation: In the model's setData() method
  • Signals: Model emits dataChanged(), rowsInserted() to notify views
python
# Model owns data and validation
class DataModel(QAbstractTableModel):
    def setData(self, index, value, role):
        if not self._validate(value):
            return False
        # update and emit dataChanged

MVVM (Model-View-ViewModel)

When to use: Same data displayed in multiple widgets with different formatting, complex UI state.

  • Model: Data source (database, API, file)
  • ViewModel: Transforms model data for display, owns UI state
  • View: PyQt widgets bound to ViewModel via signals
  • Validation: In ViewModel, before updating Model
  • Signals: ViewModel exposes Property signals; View connects to them
python
# ViewModel transforms data for display
class UserViewModel(QObject):
    display_name = Property(str, _display_name_changed)
    
    def __init__(self, user_model):
        self._user = user_model
        self._user.nameChanged.connect(self._on_model_changed)

Practical Test: Where Does Formatting Belong?

If the same data is displayed in two widgets with different formatting, the formatting belongs in a view-model/delegate, not duplicated in both widgets.

Bad:

python
# Widget A
label.setText(f"{value:.2f} €")
# Widget B  
label.setText(f"€ {value:,.2f}")

Good:

python
# ViewModel provides formatted strings
class PriceViewModel(QObject):
    display_eu = Property(str)
    display_us = Property(str)
    
    def set_price(self, value):
        self._price = value
        self.display_eu_changed.emit()
        self.display_us_changed.emit()

Signals/Slots: When Is That Enough?

Signals and slots alone are sufficient when:

  • One widget displays one data source
  • No complex derived state (e.g., "show X only if Y and Z")
  • Validation can live in the model's setData()
  • You don't need to test UI logic without the widgets

Add a ViewModel layer when:

  • Multiple views need the same data in different formats
  • UI state (enabled/disabled, visibility) depends on complex conditions
  • You want to test display logic without instantiating widgets

Where Does This Belong?

Use this routing to load only the sub-skill you need:

IntentLoad This Sub-Skill
Signal declaration, slot decorators, pyqtSignal/Signal, typed signals, connect(), disconnect(), signal chainspyqt/core
Widget composition (building custom widgets from multiple widgets), item views (QTableView, QTreeView), delegates (QItemDelegate), event filterspyqt/widgets
QThread worker-object pattern, QThreadPool/QRunnable, QExecutor, thread safety, cancellation, blocking operationspyqt/threading
Standard dialogs (QFileDialog, QMessageBox, QInputDialog, QColorDialog, QFontDialog), custom QDialog patterns, modal vs modelesspyqt/dialogs
pytest-qt fixture (qtbot), waitSignal, mouse/keyboard simulation, dialog testing, model/view testingpyqt/testing
QSS syntax, pseudo-states (:hover, :pressed), widget-specific styles, theming, platform differencespyqt/styling

What Does NOT Belong in the Hub

  • Signals/slots basics → pyqt/core (this hub only routes)
  • Widget lists → pyqt/widgets (this hub only routes)
  • QSS syntax and examples → pyqt/styling (this hub only routes)
  • Layout code snippets → pyqt/widgets (this hub only routes)

Deep Dives

Load these sub-skills for specialized topics:

  • Signals/slots deep dive → pyqt/core - Signal declaration, slot decorators, connections, typed signals
  • Widgets, layouts, item views, event handling → pyqt/widgets - Display/input/container widgets, QVBoxLayout/QHBoxLayout/QGridLayout, event filters, shortcuts
  • Signals/slots deep dive → pyqt/core - Signal declaration, slot decorators, connections, typed signals (load when declaring new signals or debugging connection issues)
  • Widgets, layouts, item views, event handling → pyqt/widgets - Display/input/container widgets, QVBoxLayout/QHBoxLayout/QGridLayout, event filters, shortcuts (load for custom widget composition)
  • QSS styling and theming → pyqt/styling - QSS syntax, pseudo-states, widget-specific styles, theming, platform differences (load before styling to avoid cross-platform bugs)
  • Dialogs → pyqt/dialogs - Standard dialogs (QFileDialog, QMessageBox, QInputDialog), custom QDialog patterns, modal/modeless
  • Threading patterns → pyqt/threading - QThread worker-object pattern, QThreadPool/QRunnable, thread safety, cancellation (critical for avoiding UI freezes)
  • pytest-qt testing → pyqt/testing - qtbot fixture, waitSignal, mouse/keyboard simulation, dialog testing, model/view testing
  • Dialogs → pyqt/dialogs - Standard dialogs (QFileDialog, QMessageBox, QInputDialog), custom QDialog patterns, modal/modeless
  • Threading patterns → pyqt/threading - QThread worker-object pattern, QThreadPool/QRunnable, thread safety, cancellation
  • pytest-qt testing → pyqt/testing - qtbot fixture, waitSignal, mouse/keyboard simulation, dialog testing, model/view testing

PyQt vs PySide Comparison

FeaturePyQt5PyQt6PySide6
LicenseGPLGPLLGPL
Qt VersionQt 5Qt 6Qt 6
MaintainedSecurity onlyActiveActive
Signal SyntaxpyqtSignalpyqtSignalSignal
Slot SyntaxpyqtSlotpyqtSlotSlot
Property SyntaxpyqtPropertypyqtPropertyProperty
Commercial UseRequires licenseRequires licenseFree
QML RegistrationqmlRegisterType()qmlRegisterType()@QmlElement

When to Use Each

  • PySide6: Recommended for most projects (LGPL, official Qt Company support)
  • PyQt6: If you need GPL compatibility or existing PyQt codebase
  • PyQt5: Legacy projects only (security fixes only)

Installation

PySide6 (Recommended)

bash
pip install PySide6

PyQt6

bash
pip install PyQt6

PyQt5 (Legacy)

bash
pip install PyQt5

Additional Dependencies

bash
# System packages (Ubuntu/Debian)
sudo apt install libgl1-mesa-glx libglib2.0-0

# System packages (Fedora)
sudo dnf install mesa-libGL glib2

# System packages (Arch)
sudo pacman -S mesa glib2

Basic Application

python
#!/usr/bin/env python3
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel
from PySide6.QtCore import Qt

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("My Application")
        self.setGeometry(100, 100, 800, 600)
        
        label = QLabel("Hello, Qt!")
        label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.setCentralWidget(label)

def main():
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

if __name__ == "__main__":
    main()

Recommended Project Structure

my_app/
├── src/
│   ├── __init__.py
│   ├── main.py
│   ├── main_window.py
│   ├── widgets/
│   │   ├── __init__.py
│   │   └── custom_widget.py
│   ├── models/
│   │   └── data_model.py
│   ├── resources/
│   │   ├── icons/
│   │   └── styles/
│   │       └── style.qss
│   └── utils/
│       └── helpers.py
├── tests/
│   └── test_main.py
├── requirements.txt
└── pyproject.toml

Quick Reference

Core Imports

python
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QPushButton, QLineEdit, QTextEdit, QComboBox, QSpinBox, QCheckBox, QSlider, QProgressBar, QGroupBox, QTabWidget, QStackedWidget, QSplitter, QListWidget, QTreeWidget, QTableWidget, QScrollArea, QToolBar, QStatusBar
from PySide6.QtCore import Qt, QObject, QTimer, QThread, Signal, Slot, Property, QSize, QPoint, QRect, QSettings, QFile, QDir, QUrl, QMimeData, QDateTime
from PySide6.QtGui import QIcon, QPixmap, QImage, QPainter, QPen, QBrush, QColor, QFont, QCursor, QKeySequence, QShortcut

Common Properties

python
widget.setEnabled(True)  # Enable/disable
widget.setVisible(False)  # Visibility
widget.setToolTip("Help")  # Tooltip
widget.setObjectName("myButton")  # QSS selector
widget.setProperty("primary", True)  # Custom property

Packaging & Distribution

PyInstaller

bash
# Install
pip install pyinstaller

# Single executable
pyinstaller --onefile --windowed app.py

# With icon and data files
pyinstaller --onefile --windowed --icon=app.ico --add-data "resources:resources" app.py

PyInstaller Spec File

python
# app.spec
a = Analysis(
    ['app.py'],
    pathex=[],
    binaries=[],
    datas=[('resources', 'resources')],
    hiddenimports=[],
    hookspath=[],
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data)
exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='MyApp',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,
    icon='app.ico',
)

cx_Freeze

python
# setup.py
from cx_Freeze import setup, Executable

build_options = {
    'packages': ['PySide6'],
    'excludes': ['tkinter'],
    'include_files': [('resources', 'resources')]
}

setup(
    name='MyApp',
    version='1.0',
    description='My Qt Application',
    options={'build_exe': build_options},
    executables=[Executable('app.py', base='Win32GUI', icon='app.ico')]
)

Build Commands

bash
# PyInstaller
pyinstaller --clean app.spec

# cx_Freeze
python setup.py build

# Create distribution
pyinstaller --clean --distpath dist app.spec

Distribution Checklist

  • Test on clean VM (no Python installed)
  • Verify all assets bundled (icons, QSS, translations)
  • Check executable size (strip debug symbols if needed)
  • Test on target OS versions
  • Sign executable (Windows/macOS)
  • Create installer (optional: NSIS, Inno Setup, dmgbuild)

Best Practices

Architecture

  1. Separate UI from business logic - Use MVC or MVVM patterns
  2. Use dependency injection - Pass dependencies to constructors
  3. Keep widgets stateless - Store state in models, not widgets
  4. Use signals for decoupling - Components communicate via signals
  5. Lazy load heavy resources - Load images/data on demand

Performance

  1. Avoid blocking the main thread - Use workers for long operations
  2. Use view delegates for complex item rendering - Don't subclass QItemDelegate unnecessarily
  3. Batch UI updates - Block signals during bulk changes
  4. Reuse widgets - Pool frequently created widgets
  5. Profile before optimizing - Use python -m cProfile

Memory Management

  1. Use parent-child relationships - Qt auto-cleans children
  2. Call deleteLater() for dynamic widgets - Don't use del directly
  3. Break signal/slot connections - Disconnect before deleting
  4. Avoid circular references - Use weak references where needed
  5. Monitor with tracemalloc - Find memory leaks

Code Organization

  1. One class per file - Keep modules focused
  2. Group related widgets - Custom widgets in separate modules
  3. Centralize constants - Use enums for fixed values
  4. Use type hints - Helps with IDE support and debugging
  5. Document public APIs - Docstrings for methods and classes

Troubleshooting

IssueCauseSolution
UI freezesBlocking operation in main threadMove to worker thread
Crashes on widget accessAccessing UI from worker threadUse signals instead
Memory leaksObjects not cleaned upUse parent-child relationships, deleteLater()
QSS not applyingWrong selector or syntaxCheck widget objectName, use style().polish()
Signals not firingWrong connection typeVerify signal declaration, check thread affinity
High CPU usageTight loop in main threadUse timers or workers
Window not showingMissing show() callCall window.show() before app.exec()
Icons not loadingWrong path or formatUse QResource for bundled assets

Debugging Tips

python
# Enable Qt logging
import logging
logging.basicConfig(level=logging.DEBUG)

# Check for unhandled exceptions
import sys
sys.excepthook = lambda exc: print(f"Unhandled: {exc}")

# Print widget hierarchy
print(window.findChildren(QWidget))

# Check signal connections
print(button.receivers(button.clicked))

# Dump QSS errors
app.setStyleSheet("INVALID {")  # Will print parse errors

References

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة أثناء تحميل المهارة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Pyqt؟

Use when building cross-platform desktop apps with PyQt6 or PySide6 - hub for installation, project structure, signals and slots basics, and pointers to widgets, styling, dialogs, threading, and testing sub-skills

لماذا تستخدم Pyqt على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Pyqt عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Pyqt في TypingMind؟

افتح الإضافات → المهارات → التثبيت من GitHub في TypingMind والصق https://github.com/CodeAtCode/oss-ai-skills/tree/master/frameworks/pyqt. يقرأ TypingMind ملف SKILL.md الخاص بها، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Pyqt؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Pyqt؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Pyqt معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Pyqt مجانية؟

نعم. نشرها CodeAtCode على GitHub بموجب ترخيص GPL-3.0. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا البريدية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇