Skip to main content

[ 中文 | English ]

A modern, composable UI component library for Qt 6 / QML, inspired by shadcn/ui.

Qt 6 / QML 可组合 UI 组件库,对齐 shadcn/ui 的设计哲学:Design Token → Component → Composition → Theme。

⚠️ 开发状态:本项目仍在活跃开发中,API 可能随迭代调整。已可用组件与里程碑进度见 文档站里程碑 与 Skills,欢迎 Issue 与 PR。

🐍 PyQt6 / PySide6 纯 Python 适配:可通过 PyPI 安装:pip install pyqtshadcn 或 pip install pysideshadcn。更多信息见 Python 绑定。

✨ 特性

  • Design Token 驱动 — 语义化颜色 / 圆角 / 间距 token,theme.mode = "dark" 全局随动
  • QML 管 UI,C++ 管能力 — Theme 引擎、Icon 注册、Model 等能力层落在 C++,不退化成一个「QML 样式库」
  • 复用 Qt Quick Controls — 键盘导航、Focus、无障碍开箱即得,只做视觉与组件 API
  • 可组合组件 — Card = CardHeader / CardContent / CardFooter,对齐 shadcn/ui 组合方式

🚀 快速开始

要求:Qt 6.5+、CMake 3.24+

不支持 Qt 5。 本库用到 required property(Qt 6.0+)、pragma ComponentBehavior: Bound 与 MultiEffect(6.5+),并依赖 Qt 6 重写后的 TableView —— 这些在 Qt 5.15 上都没有 等价物,不是加条件编译能绕开的。评估过程与替代方案见 issue #12。

git clone https://github.com/QtShadcn/qtshadcn.git
cd qtshadcn

# 构建(默认 QT_PREFIX=$HOME/Qt/6.11.1/macos,可用环境变量覆盖)
make build

# 运行 showcase(Design Token 色板演示,明暗切换;需真实桌面,不要用沙箱)
make run

或手动:

cmake -S . -B build -DCMAKE_PREFIX_PATH="${QT_PREFIX:-$HOME/Qt/6.11.1/macos}" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build
./build/bin/showcase

Linux 把前缀里的 macos 换成 gcc_64;Homebrew 用 QT_PREFIX=$(brew --prefix qt)。

📦 接入你的项目

三种方式任选其一。作为子项目引入时默认不编 showcase。

方式一:find_package(预编译安装,最省事)

cmake -S . -B build -DCMAKE_PREFIX_PATH="$HOME/Qt/6.11.1/macos"
cmake --build build
cmake --install build --prefix /your/prefix
find_package(QtShadcn 0.2 REQUIRED)
target_link_libraries(myapp PRIVATE QtShadcn::QtShadcn Qt6::Quick)

链接上 QtShadcn::QtShadcn 就够 import QtShadcn —— qmldir 里是 prefer :/qt/qml/QtShadcn/,QML 模块(qmldir、类型信息、全部 .qml)已编译进库资源的, 运行时不用设 QML_IMPORT_PATH。安装出去的磁盘副本在 <prefix>/lib/qml/QtShadcn(CMake 里变量 QtShadcn_QML_IMPORT_PATH),只给 qmllint / qmlls / Qt Designer 这类工具链用。

方式二:FetchContent(锁版本 tag,无需 submodule)

include(FetchContent)
FetchContent_Declare(qtshadcn
    GIT_REPOSITORY https://github.com/QtShadcn/qtshadcn.git
    GIT_TAG        v0.2.0)   # 锁定 release tag;升级 = 改这一行
FetchContent_MakeAvailable(qtshadcn)
target_link_libraries(myapp PRIVATE QtShadcn Qt6::Quick Qt6::QuickControls2)

CPM.cmake 用户等价写法:CPMAddPackage("gh:QtShadcn/qtshadcn@v0.2.0")。

方式三:submodule / clone 到 third_party(便于本地改库源码)

mkdir -p third_party
git submodule add https://github.com/QtShadcn/qtshadcn.git third_party/qtshadcn
# 或:git clone https://github.com/QtShadcn/qtshadcn.git third_party/qtshadcn
find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Qml QuickControls2 Svg Network)
add_subdirectory(third_party/qtshadcn)
target_link_libraries(myapp PRIVATE QtShadcn Qt6::Quick Qt6::QuickControls2)

submodule 锁版本同样用 tag:cd third_party/qtshadcn && git fetch --tags && git checkout v0.2.0。

main.cpp 里必须 QQuickStyle::setStyle("Basic")(macOS 默认 native style 会拒绝自定义 contentItem / background)。

什么时候需要 QML_IMPORT_PATH:只有「不链接库、纯靠 import 路径加载」的场合(例如只跑 .qml 文件、或给 qmllint 指路)。链接了 QtShadcn 的应用不需要它——模块内容在库资源里。 QML_IMPORT_PATH 要指到模块目录的父路径(如 build/src,而不是 build/src/QtShadcn)。

建议在应用根目录放 Makefile(make build / make run / make clean)。完整工程模板见 skills/qtshadcn/references/consumer/build.md。

🎨 用法示例

QML 侧 import QtShadcn 即可使用组件与主题(C++ 侧需 Basic style,见上文):

import QtQuick
import QtShadcn          // 组件 + 主题入口

Window {
    width: 640
    height: 480
    visible: true

    // 主题入口(必做):声明式绑定 C++ ThemeManager 的 token 字典
    QtShadcnTheme { id: theme }

    color: theme.background   // 窗口底色跟主题走

    ShadcnButton {
        anchors.centerIn: parent
        text: qsTr("Deploy")
        variant: ShadcnButton.Variant.Primary
        iconName: "rocket"                       // lucide 图标(可选)
        onClicked: theme.mode = theme.mode === "dark" ? "light" : "dark"
    }
}
  • 主题接入:任何使用组件的页面先放一个 QtShadcnTheme;theme.mode = "dark" 全局随动
  • 运行时改主色:ThemeManager.primary = "#2563eb"(空串恢复默认)
  • 完整组件用法见 组件文档 或仓库内 skills

Python 绑定

pyqtshadcn 用纯 Python 实现 ThemeManager 和 IconRegistry 两个 QML 单例,无需编译 C++ 插件, 避免与 PyQt6 自带 Qt 的 ABI 不匹配。需要 Python ≥ 3.10 与 PyQt6 ≥ 6.10(pip 会自动安装 PyQt6)。

pysideshadcn 提供面向 PySide6 的同一适配,只依赖 PySide6。请按应用所使用的 Qt 绑定选择对应的发行包。

示例代码:
import sys

from PyQt6.QtCore import QUrl
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine
from pyqtshadcn import setup

app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()

# 添加包内 QML import path,并注册 ThemeManager 和 IconRegistry 单例
setup(engine)

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())

本地开发

在本仓库根目录运行:

python -m venv .venv && source .venv/bin/activate
pip install -e .
QT_QPA_PLATFORM=offscreen python examples/prototype/main.py

示例会进入 Qt 事件循环,验证完成后可用 Ctrl+C 退出。构建时直接从 src/qml 和 src/assets/icons 打包 QML 与图标。修改这些资源后需重新运行 pip install -e .。

已知限制

  • ShadcnCommand* 系列未纳入 Python 包,因为其依赖的 C++ 评分器尚未移植。
  • ShadcnTableModel 尚未从 C++ 移植到 Python,因此目前无法使用 ShadcnTable。
  • IconRegistry 仅支持随包附带的 SVG 图标,目前尚不支持 C++ 版的远程 CDN 下载和磁盘缓存。

📄 文档

🤖 AI 如何使用 QtShadcn(Skills)

仓库内的 skills/ 目录是教 AI 助手使用 / 扩展本组件库的指南(格式对齐 slidev/skills)。根据角色分两类:

① 使用者 —— 把库接入自己的工程、用组件写业务(skills/qtshadcn/)

适用:消费方开发者 + 其 AI 助手,目标是快速接库并用组件搭界面。

  • SKILL.md —— 入口:接入铁律(CMake + 根 Makefile + add_subdirectory(.../src) + Basic style)+ 组件索引 + 使用坑
  • build.md —— 消费方最小工程模板(CMake / main.cpp / Makefile / QML_IMPORT_PATH)
  • references/ —— 主题 / 图标 + 各组件用法、属性、坑

安装:帮我安装这个 https://github.com/QtShadcn/qtshadcn/skills/qtshadcn/SKILL.md skills

使用:请先读 https://github.com/QtShadcn/qtshadcn/skills/qtshadcn/SKILL.md,然后用 ShadcnDialog 帮我写一个确认弹窗。

② 开发组件 —— 扩展本库、新增 / 修改组件(skills/qtshadcn-dev/)

适用:需要扩展 QtShadcn 本身的贡献者 + 其 AI 助手,目标是按规范新增组件并同步文档与截图。

  • SKILL.md —— 入口:开发铁律(先抓 shadcn 参考 → 对照表 → 确认)+ 架构要点 + 开发坑 + 「新增组件后必做」
  • workflow.md —— 组件开发全流程:抓 shadcn 参考 → 列对照表 → 实现 → showcase 验证 → 关 Issue
  • build.md —— 本仓库构建 / 静态验证 / qmlcache / 截图 / showcase 结构
  • technical-design.md —— 架构与 Token 规范依据
  • component-workflow.md —— 人读版组件开发流程

使用:请先读 skills/qtshadcn-dev/references/workflow.md,按清单新增一个 ShadcnXxx 组件,并在 showcase 加演示页、更新两个 skill 的组件索引。

License

MIT © QtShadcn

本项目与 shadcn/ui 官方无隶属关系,仅在组件设计上受其启发。

第三方素材

Metadata

Release files for pyqtshadcn 0.2.1

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.2.1
File Size Uploaded Provenance Actions
pyqtshadcn-0.2.1.tar.gz 135.2 kB With provenance Details for pyqtshadcn-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 356.7 kB

Release files / pyqtshadcn-0.2.1.tar.gz

Download URL pyqtshadcn-0.2.1.tar.gz
Size 135.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2e67ee25441d41ee5e184468425594b9c1917b2818e4ab891b854daf543f244d
BLAKE2b-256 checksum
How to use checksums
f92b1eec78abd13620728f9afdfb78c963941cb9d52034319fe8d3451cd2f6e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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

Download URL pyqtshadcn-0.2.1-py3-none-any.whl
Size 221.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
131b429756629f70ed68538e3b1e2b436265f4dda491880b88fb2a53aea75dff
BLAKE2b-256 checksum
How to use checksums
37544bd731e09b146e689906502b053e1333603f05840552a951fc37975a2094
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for pyqtshadcn 0.2.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyqtshadcn-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.2.1 This release

2 release files Full 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