1 Star 0 Fork 0

wuudouglas/Qt-Frameless-Window-DarkStyle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DarkStyle.cpp 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
/*
###############################################################################
# #
# The MIT License #
# #
# Copyright (C) 2017 by Juergen Skrotzky (JorgenVikingGod@gmail.com) #
# >> https://github.com/Jorgen-VikingGod #
# #
# Sources: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle #
# #
###############################################################################
*/
#include "DarkStyle.h"
DarkStyle::DarkStyle() : DarkStyle(styleBase()) {}
DarkStyle::DarkStyle(QStyle *style) : QProxyStyle(style) {}
QStyle *DarkStyle::styleBase(QStyle *style) const {
static QStyle *base =
!style ? QStyleFactory::create(QStringLiteral("Fusion")) : style;
return base;
}
QStyle *DarkStyle::baseStyle() const { return styleBase(); }
void DarkStyle::polish(QPalette &palette) {
// modify palette to dark
palette.setColor(QPalette::Window, QColor(53, 53, 53));
palette.setColor(QPalette::WindowText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::WindowText,
QColor(127, 127, 127));
palette.setColor(QPalette::Base, QColor(42, 42, 42));
palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
palette.setColor(QPalette::ToolTipBase, Qt::white);
palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
palette.setColor(QPalette::Text, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
palette.setColor(QPalette::Dark, QColor(35, 35, 35));
palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
palette.setColor(QPalette::Button, QColor(53, 53, 53));
palette.setColor(QPalette::ButtonText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::ButtonText,
QColor(127, 127, 127));
palette.setColor(QPalette::BrightText, Qt::red);
palette.setColor(QPalette::Link, QColor(42, 130, 218));
palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
palette.setColor(QPalette::HighlightedText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
QColor(127, 127, 127));
}
void DarkStyle::polish(QApplication *app) {
if (!app) return;
// increase font size for better reading,
// setPointSize was reduced from +2 because when applied this way in Qt5, the
// font is larger than intended for some reason
QFont defaultFont = QApplication::font();
defaultFont.setPointSize(defaultFont.pointSize() + 1);
app->setFont(defaultFont);
// loadstylesheet
QFile qfDarkstyle(QStringLiteral(":/darkstyle/darkstyle.qss"));
if (qfDarkstyle.open(QIODevice::ReadOnly | QIODevice::Text)) {
// set stylesheet
QString qsStylesheet = QString::fromLatin1(qfDarkstyle.readAll());
app->setStyleSheet(qsStylesheet);
qfDarkstyle.close();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuudouglas/Qt-Frameless-Window-DarkStyle.git
git@gitee.com:wuudouglas/Qt-Frameless-Window-DarkStyle.git
wuudouglas
Qt-Frameless-Window-DarkStyle
Qt-Frameless-Window-DarkStyle
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385