aiohttp
免费Use when building Python async HTTP services or clients with aiohttp - web server routing, middleware, WebSocket, SSE, streaming, client sessions, pytest-aiohttp testing, or troubleshooting SSL and timeout issues
中文简介正在准备中。当前显示原文说明。
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
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
PyQt and PySide are Python bindings for the Qt application framework for building cross-platform desktop applications.
For detailed information, see the specialized sub-skills:
| Skill | Description | Path |
|---|---|---|
| pyqt-core | Signals, slots, timers, settings, file I/O | core/SKILL.md |
| pyqt-widgets | All widgets and layouts | widgets/SKILL.md |
| pyqt-threading | QThread, thread pools, concurrency | threading/SKILL.md |
| pyqt-dialogs | Standard and custom dialogs | dialogs/SKILL.md |
| pyqt-testing | pytest-qt testing patterns | testing/SKILL.md |
| pyqt-styling | QSS styling and themes | styling/SKILL.md |
| pyqt-multimedia | Audio, video, camera, recording | multimedia/SKILL.md |
Qt supports multiple architectural patterns. Choose based on your data-display complexity.
When to use: Simple data display with inline editing, standard item views.
QAbstractItemModel subclass owns the dataQTableView, QTreeView, QListView displays datasetData() methoddataChanged(), rowsInserted() to notify views# 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
When to use: Same data displayed in multiple widgets with different formatting, complex UI state.
Property signals; View connects to them# 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)
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:
# Widget A
label.setText(f"{value:.2f} €")
# Widget B
label.setText(f"€ {value:,.2f}")
Good:
# 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 and slots alone are sufficient when:
setData()Add a ViewModel layer when:
Use this routing to load only the sub-skill you need:
| Intent | Load This Sub-Skill |
|---|---|
Signal declaration, slot decorators, pyqtSignal/Signal, typed signals, connect(), disconnect(), signal chains | pyqt/core |
| Widget composition (building custom widgets from multiple widgets), item views (QTableView, QTreeView), delegates (QItemDelegate), event filters | pyqt/widgets |
QThread worker-object pattern, QThreadPool/QRunnable, QExecutor, thread safety, cancellation, blocking operations | pyqt/threading |
| Standard dialogs (QFileDialog, QMessageBox, QInputDialog, QColorDialog, QFontDialog), custom QDialog patterns, modal vs modeless | pyqt/dialogs |
pytest-qt fixture (qtbot), waitSignal, mouse/keyboard simulation, dialog testing, model/view testing | pyqt/testing |
QSS syntax, pseudo-states (:hover, :pressed), widget-specific styles, theming, platform differences | pyqt/styling |
pyqt/core (this hub only routes)pyqt/widgets (this hub only routes)pyqt/styling (this hub only routes)pyqt/widgets (this hub only routes)Load these sub-skills for specialized topics:
pyqt/core - Signal declaration, slot decorators, connections, typed signalspyqt/widgets - Display/input/container widgets, QVBoxLayout/QHBoxLayout/QGridLayout, event filters, shortcutspyqt/styling - QSS syntax, pseudo-states, widget-specific styles, property-based stylingpyqt/dialogs - Standard dialogs (QFileDialog, QMessageBox, QInputDialog), custom QDialog patterns, modal/modelesspyqt/threading - QThread worker-object pattern, QThreadPool/QRunnable, thread safety, cancellationpyqt/testing - qtbot fixture, waitSignal, mouse/keyboard simulation, dialog testing, model/view testing| Feature | PyQt5 | PyQt6 | PySide6 |
|---|---|---|---|
| License | GPL | GPL | LGPL |
| Qt Version | Qt 5 | Qt 6 | Qt 6 |
| Maintained | Security only | Active | Active |
| Signal Syntax | pyqtSignal | pyqtSignal | Signal |
| Slot Syntax | pyqtSlot | pyqtSlot | Slot |
| Property Syntax | pyqtProperty | pyqtProperty | Property |
| Commercial Use | Requires license | Requires license | Free |
| QML Registration | qmlRegisterType() | qmlRegisterType() | @QmlElement |
pip install PySide6
pip install PyQt6
pip install PyQt5
# 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
#!/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()
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
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
widget.setEnabled(True) # Enable/disable
widget.setVisible(False) # Visibility
widget.setToolTip("Help") # Tooltip
widget.setObjectName("myButton") # QSS selector
widget.setProperty("primary", True) # Custom property
# 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
# 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',
)
# 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')]
)
# PyInstaller
pyinstaller --clean app.spec
# cx_Freeze
python setup.py build
# Create distribution
pyinstaller --clean --distpath dist app.spec
python -m cProfiledeleteLater() for dynamic widgets - Don't use del directlytracemalloc - Find memory leaks| Issue | Cause | Solution |
|---|---|---|
| UI freezes | Blocking operation in main thread | Move to worker thread |
| Crashes on widget access | Accessing UI from worker thread | Use signals instead |
| Memory leaks | Objects not cleaned up | Use parent-child relationships, deleteLater() |
| QSS not applying | Wrong selector or syntax | Check widget objectName, use style().polish() |
| Signals not firing | Wrong connection type | Verify signal declaration, check thread affinity |
| High CPU usage | Tight loop in main thread | Use timers or workers |
| Window not showing | Missing show() call | Call window.show() before app.exec() |
| Icons not loading | Wrong path or format | Use QResource for bundled assets |
# 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
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Use when building Python async HTTP services or clients with aiohttp - web server routing, middleware, WebSocket, SSE, streaming, client sessions, pytest-aiohttp testing, or troubleshooting SSL and timeout issues
中文简介正在准备中。当前显示原文说明。
Use when doing structural code search and rewriting - ast-grep linting, refactoring, multi-language patterns
中文简介正在准备中。当前显示原文说明。
Use when building GBA games with the BPCore Lua engine - entity, sprite and tilemap functions, SRAM save and load, link cable multiplayer protocol, camera and scrolling, or optimization patterns
中文简介正在准备中。当前显示原文说明。
Use when running background tasks with Celery - worker and broker configuration (Redis, RabbitMQ), task routing by name vs queue, chains/groups/chords, retry patterns (autoretry_for, retry_backoff), acks_late semantics, failure detection, and monitoring with Flower
中文简介正在准备中。当前显示原文说明。
Use when building Django applications - security hardening, authentication and permissions, ORM optimization, PostgreSQL features, Django 6.0, migrations, testing, and ecosystem libraries
中文简介正在准备中。当前显示原文说明。
Use when customizing Django Admin - save_formset, get_search_results, formsets, queryset optimization, db_index, custom URLs
中文简介正在准备中。当前显示原文说明。