| File | Date | Author | Commit |
|---|---|---|---|
| .github | 2025-02-08 |
|
[481ee0] 添加构建 CI |
| 3rdparty | 2025-02-08 |
|
[0130b5] 添加 Python 打包配置 |
| debian | 2025-03-03 |
|
[1874c1] 更新版本号 |
| demo | 2025-02-22 |
|
[5c06b0] fix bug |
| doc | 2024-11-25 |
|
[5f1161] 更换预览图,避免 README 卡顿 |
| src | 2025-03-03 |
|
[1874c1] 更新版本号 |
| tool | 2025-02-22 |
|
[a9f70c] 内边距调整 |
| .gitignore | 2025-02-13 |
|
[b8e81f] 增加 deb 打包配置 |
| .gitmodules | 2024-10-04 |
|
[be7e0a] 完全重构并修改协议 |
| CMakeLists.txt | 2025-02-20 |
|
[ad03da] 移除静态库 |
| LICENSE | 2024-10-04 |
|
[be7e0a] 完全重构并修改协议 |
| README.md | 2025-02-14 |
|
[c6e7fc] 使导出资源的路径与内部路径保持一致 |
Qt theme in pure qss - 纯 qss 的 Qt 主题
Preview and Export Resource Package Online - 在线预览和导出资源包


QtTheme is a pure QSS project, no language restrictions, use C++ description here.
Export the resource package from here, and add it to your project.
Use QMainWindow::setStyleSheet to set the global style.
c++
QFile file(":/QtTheme/theme/Flat/Dark/Blue/Pink.qss");
file.open(QFile::ReadOnly);
setStyleSheet(file.readAll());
QWdiget::setProperty to set the color.c++
auto button = new QPushButton(tr("Button"));
button->setProperty("Color", "Primary");| Color | Explain |
|---|---|
| Primary | The primary color selected when exporting |
| Secondary | The secondary color selected when exporting |
| Success | The success color( ) |
| Warning | The warning color( ) |
| Danger | The error color( ) |
QtTheme 是纯 QSS 的项目,不受语言限制,这里使用 C++ 描述。
在这里导出资源包,然后将其加入你的项目。
使用 QMainWindow::setStyleSheet 设置全局样式。
c++
QFile file(":/QtTheme/theme/Flat/Dark/Blue/Pink.qss");
file.open(QFile::ReadOnly);
setStyleSheet(file.readAll());
使用 QWdiget::setProperty 设置颜色。
c++
auto button = new QPushButton(tr("Button"));
button->setProperty("Color", "Primary");
| 颜色 | 说明 |
|---|---|
| Primary | 导出时选择的主要颜色 |
| Secondary | 导出时选择的次要颜色 |
| Success | 成功色( ) |
| Warning | 警告色( ) |
| Danger | 危险色( ) |
Customized QWidget subclasses must override paintEvent, otherwise the style will not take effect on this class:
自定义的 QWidget 子类,必须重载 paintEvent,否则样式不会再该类上生效:
https://doc.qt.io/qt-6/stylesheet-reference.html#qwidget-widget
void CustomWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Style will not update itself automatically when the value of a property referenced from the style sheet changes, you must update it manually:
当样式表引用的属性值发生变化时,样式不会自动更新,必须手动更新:
// property changes
widget->setProperty("Color", "Secondary");
// update style manually
widget->style()->unpolish(widget);
widget->style()->polish(widget);
QComboBox must set the view for the internal style to take effect:
QComboBox 必须设置 view, 内部的样式才能生效:
https://doc.qt.io/qt-6/stylesheet-reference.html#qcombobox-widget
comboBox->setView(new QListView);
Install - 安装:
pip install QtTheme
Usage - 使用:
This method will include all resources of QtTheme.
It is recommended to export the resource package from here,
and add it to your project by RCC (pyrcc5orpyside6-rcc).这种方式将会包含 QtTheme 的全部资源。
建议从 这里 导出资源包,
然后通过 RCC (pyrcc5orpyside6-rcc) 将它加入你的项目。
Dependencies - 依赖
qtbase5-dev, qttools5-dev qt6-base-dev, qt6-tools-dev qt5-qtbase-devel, qt5-qttools-devel qt6-qtbase-devel, qt6-qttools-devel git clone git@github.com:hubenchang0515/QtTheme.git
cd QtTheme
git submodule update --init
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --parallel
AGPL-3.0-or-later MIT