Skip to main content

pyqtshadcn

QtShadcn 组件库的 PyQt6 纯 Python 适配包——无需 C++ 编译,安装即用。

对应主仓库 qtshadcn 的 QML 组件,本包用纯 Python 重写其 C++ 能力层(ThemeManager / IconRegistry 两个 QML singleton),使 PyQt6 引擎可直接加载 原仓库的 30+ 个 QML 组件(零修改复用)。

为什么不用 C++ 插件

主仓库的 C++ 插件针对特定 Qt 小版本编译,而 pip 的 PyQt6 自带另一版本 Qt,ABI 不匹配时 QML 引擎会拒绝加载插件。本包的能力层用 Python 实现、与 PyQt6 自带 Qt 同 ABI,安装即跑。

安装

pip install pyqtshadcn

需要 Python ≥ 3.10 与 PyQt6 ≥ 6.10(pip 会自动安装 PyQt6 依赖)。

用法

import sys
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine
from PyQt6.QtCore import QUrl

from pyqtshadcn import setup   # 一行接入

app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
setup(engine)                 # 注册 singleton + 添加 QML import path

engine.loadData(b"""
import QtQuick
import QtQuick.Controls.Basic
import QtShadcn
Window {
    width: 400; height: 300; visible: true
    QtShadcnTheme { id: theme }
    ShadcnButton { text: "Hello"; onClicked: theme.mode = "dark" }
}
""", QUrl("qrc:/main.qml"))

sys.exit(app.exec())

setup(engine) 做两件事:

  1. engine.addImportPath(<包内 QtShadcn 目录>) —— 使 QML 中 import QtShadcn 可解析
  2. 注册 ThemeManager / IconRegistry 为 QML singleton

本地开发运行

git clone https://github.com/QtShadcn/pyqtshadcn
cd pyqtshadcn
python -m venv .venv && source .venv/bin/activate
pip install -e . PyQt6

# 无界面验证(无需显示器)
QT_QPA_PLATFORM=offscreen python examples/prototype_main.py

与主仓库的同步

包内的 qml/ 与 icons/ 是主仓库 src/qml、src/assets/icons 的副本(发布时打包进 wheel)。 主仓库更新组件后,运行同步脚本拉取最新副本:

python sync.py --src /path/to/qtshadcn     # 写文件
python sync.py --src /path/to/qtshadcn --check   # 仅检查是否过期(CI 用)

同步会自动排除 ShadcnTable(见下)并校验 qmldir 与目录一致。

已知限制

  1. ShadcnTable 暂不支持:该组件依赖主仓库 C++ 的 ShadcnTableModel(QAbstractTableModel 子类)。 纯 Python 路线下尚未用 QAbstractTableModel 移植,故包内未包含此组件。
  2. IconRegistry 仅实现本地内置图标(随包附带的 75 个 svg),未实现主仓库 C++ 版的 远程 CDN 兜底(lucide 按需下载 + 磁盘缓存)。
  3. 组件 QML 内已用 import QtQuick.Controls.Basic 强制 Basic 风格(token 自绘的前提), 不依赖 C++ 侧设置样式。

许可

与主仓库一致(MIT)。

Metadata

Release files for pyqtshadcn 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyqtshadcn 0.1.0
File Size Uploaded Provenance Actions
pyqtshadcn-0.1.0.tar.gz 41.6 kB Without provenance Details for pyqtshadcn-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyqtshadcn 0.1.0
File Interpreter ABI Platform Actions
pyqtshadcn-0.1.0-py3-none-any.whl Python 3 none any Details for pyqtshadcn-0.1.0-py3-none-any.whl

Total release size: 125.1 kB

Release files / pyqtshadcn-0.1.0.tar.gz

Download URL pyqtshadcn-0.1.0.tar.gz
Size 41.6 kB
Tags Source
SHA-256 checksum
How to use checksums
386a9352564883dda4edacd4745f49f818fdd15bea8a96b557a6779103c4df87
BLAKE2b-256 checksum
How to use checksums
25a4abad4d79aff604206b1dd0e9a836bbe1b10ff6e0e57cf4c5ddea23f60e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / pyqtshadcn-0.1.0-py3-none-any.whl

Download URL pyqtshadcn-0.1.0-py3-none-any.whl
Size 83.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57d83477a8d68e229d96c50696d4960b9ba4a2d4e6c086d4939528bea0767749
BLAKE2b-256 checksum
How to use checksums
0ff0b36b864c292590b1d3582eb88d947ad3dbcfe95bb1ce8e821f1a3626d5b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for pyqtshadcn 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page