Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
407839f7
P
PyQt Fluent Widgets
项目概览
k54kdk
/
PyQt Fluent Widgets
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PyQt Fluent Widgets
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
407839f7
编写于
6月 21, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加更换 svg 图标颜色的功能
上级
88fb2c71
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
212254 addition
and
212268 deletion
+212254
-212268
examples/gallery/app/common/resource.py
examples/gallery/app/common/resource.py
+212183
-212224
examples/gallery/app/resource/qss/dark/gallery_interface.qss
examples/gallery/app/resource/qss/dark/gallery_interface.qss
+6
-11
examples/gallery/app/resource/qss/dark/home_interface.qss
examples/gallery/app/resource/qss/dark/home_interface.qss
+1
-2
examples/gallery/app/resource/qss/dark/main_window.qss
examples/gallery/app/resource/qss/dark/main_window.qss
+2
-6
examples/gallery/app/resource/qss/light/gallery_interface.qss
...ples/gallery/app/resource/qss/light/gallery_interface.qss
+9
-12
qfluentwidgets/common/config.py
qfluentwidgets/common/config.py
+1
-0
qfluentwidgets/common/icon.py
qfluentwidgets/common/icon.py
+49
-12
qfluentwidgets/components/widgets/label.py
qfluentwidgets/components/widgets/label.py
+3
-1
未找到文件。
examples/gallery/app/common/resource.py
浏览文件 @
407839f7
此差异已折叠。
点击以展开。
examples/gallery/app/resource/qss/dark/gallery_interface.qss
浏览文件 @
407839f7
...
...
@@ -15,6 +15,12 @@ ToolBar>CaptionLabel {
ExampleCard {
background-color: transparent;
color: white;
}
TitleLabel,
StrongBodyLabel {
color: white;
}
ExampleCard>#card {
...
...
@@ -28,12 +34,6 @@ ExampleCard>#card QLabel {
color: white;
}
ExampleCard>#titleLabel {
font: 14px 'Segoe UI Light', 'Microsoft YaHei';
background-color: transparent;
font-weight: 700;
color: white;
}
#sourceWidget {
background-color: rgb(51, 51, 51);
...
...
@@ -41,8 +41,3 @@ ExampleCard>#titleLabel {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
#sourcePathLabel {
color: white;
font: 14px 'Segoe UI', 'Microsoft YaHei';
}
examples/gallery/app/resource/qss/dark/home_interface.qss
浏览文件 @
407839f7
...
...
@@ -10,8 +10,7 @@ QScrollArea {
BannerWidget > #galleryLabel {
font: 42px 'Segoe UI', 'Microsoft YaHei';
font-weight: bold;
font: 42px 'Segoe UI SemiBold', 'Microsoft YaHei SemiBold';
background-color: transparent;
color: white;
padding-left: 28px;
...
...
examples/gallery/app/resource/qss/dark/main_window.qss
浏览文件 @
407839f7
...
...
@@ -15,16 +15,12 @@ CustomTitleBar {
background-color: transparent;
}
CustomTitleBar > QLabel,
Widget > QLabel {
color: white;
}
CustomTitleBar>QLabel#titleLabel {
background: transparent;
font: 13px 'Segoe UI';
padding: 0 4px
padding: 0 4px;
color: white;
}
MinimizeButton {
...
...
examples/gallery/app/resource/qss/light/gallery_interface.qss
浏览文件 @
407839f7
...
...
@@ -6,6 +6,10 @@ QScrollArea {
border: none;
}
ToolBar > StrongBodyLabel {
color: black;
}
ToolBar > CaptionLabel {
color: rgb(95, 95, 95);
}
...
...
@@ -14,6 +18,11 @@ ExampleCard {
background-color: transparent;
}
TitleLabel,
StrongBodyLabel {
color: black;
}
ExampleCard > #card {
border: 1px solid rgb(234, 234, 234);
border-radius: 10px;
...
...
@@ -25,21 +34,9 @@ ExampleCard > #card QLabel {
color: black;
}
ExampleCard > #titleLabel {
font: 14px 'Segoe UI Light', 'Microsoft YaHei';
font-weight: 700;
background-color: transparent;
color: black;
}
#sourceWidget {
background-color: rgb(253, 253, 253);
border-top: 1px solid rgb(234, 234, 234);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
#sourcePathLabel {
color: black;
font: 14px 'Segoe UI', 'Microsoft YaHei';
}
qfluentwidgets/common/config.py
浏览文件 @
407839f7
...
...
@@ -346,6 +346,7 @@ class QConfig(QObject):
"""
if
isinstance
(
config
,
QConfig
):
self
.
_cfg
=
config
self
.
_cfg
.
themeChanged
.
connect
(
self
.
themeChanged
)
if
isinstance
(
file
,
(
str
,
Path
)):
self
.
_cfg
.
file
=
Path
(
file
)
...
...
qfluentwidgets/common/icon.py
浏览文件 @
407839f7
...
...
@@ -3,8 +3,8 @@ from enum import Enum
from
typing
import
Union
from
PyQt5.QtXml
import
QDomDocument
from
PyQt5.QtCore
import
QRectF
,
Qt
,
QFile
,
QObject
from
PyQt5.QtGui
import
QIcon
,
QIconEngine
from
PyQt5.QtCore
import
QRectF
,
Qt
,
QFile
,
QObject
,
QRect
from
PyQt5.QtGui
import
QIcon
,
QIconEngine
,
QColor
,
QPixmap
,
QImage
,
QPainter
from
PyQt5.QtWidgets
import
QAction
from
PyQt5.QtSvg
import
QSvgRenderer
...
...
@@ -12,7 +12,6 @@ from .config import isDarkTheme, Theme
from
.overload
import
singledispatchmethod
class
MenuIconEngine
(
QIconEngine
):
def
__init__
(
self
,
icon
):
...
...
@@ -39,6 +38,30 @@ class MenuIconEngine(QIconEngine):
painter
.
restore
()
class
SvgIconEngine
(
QIconEngine
):
""" Svg icon engine """
def
__init__
(
self
,
svg
:
str
):
super
().
__init__
()
self
.
svg
=
svg
def
paint
(
self
,
painter
,
rect
,
mode
,
state
):
drawSvgIcon
(
self
.
svg
.
encode
(),
painter
,
rect
)
def
clone
(
self
)
->
QIconEngine
:
return
SvgIconEngine
(
self
.
svg
)
def
pixmap
(
self
,
size
,
mode
,
state
):
image
=
QImage
(
size
,
QImage
.
Format_ARGB32
)
image
.
fill
(
Qt
.
transparent
)
pixmap
=
QPixmap
.
fromImage
(
image
,
Qt
.
NoFormatConversion
)
painter
=
QPainter
(
pixmap
)
rect
=
QRect
(
0
,
0
,
size
.
width
(),
size
.
height
())
self
.
paint
(
painter
,
rect
,
mode
,
state
)
return
pixmap
def
getIconColor
(
theme
=
Theme
.
AUTO
,
reverse
=
False
):
""" get the color of icon based on theme """
if
not
reverse
:
...
...
@@ -143,7 +166,7 @@ def drawIcon(icon, painter, rect, **attributes):
class
FluentIconBase
:
""" Fluent icon base class """
def
path
(
self
,
theme
=
Theme
.
AUTO
):
def
path
(
self
,
theme
=
Theme
.
AUTO
)
->
str
:
""" get the path of icon
Parameters
...
...
@@ -156,7 +179,7 @@ class FluentIconBase:
"""
raise
NotImplementedError
def
icon
(
self
,
theme
=
Theme
.
AUTO
):
def
icon
(
self
,
theme
=
Theme
.
AUTO
,
color
:
QColor
=
None
):
""" create an fluent icon
Parameters
...
...
@@ -166,8 +189,17 @@ class FluentIconBase:
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
color: QColor | Qt.GlobalColor | str
icon color, only applicable to svg icon
"""
return
QIcon
(
self
.
path
(
theme
))
path
=
self
.
path
(
theme
)
if
not
(
path
.
endswith
(
'.svg'
)
and
color
):
return
QIcon
(
self
.
path
(
theme
))
color
=
QColor
(
color
).
name
()
return
QIcon
(
SvgIconEngine
(
writeSvg
(
path
,
fill
=
color
)))
def
render
(
self
,
painter
,
rect
,
theme
=
Theme
.
AUTO
,
indexes
=
None
,
**
attributes
):
""" draw svg icon
...
...
@@ -192,12 +224,17 @@ class FluentIconBase:
**attributes:
the attributes of modified path
"""
if
attributes
:
svg
=
writeSvg
(
self
.
path
(
theme
),
indexes
,
**
attributes
).
encode
()
else
:
svg
=
self
.
path
(
theme
)
icon
=
self
.
path
(
theme
)
drawSvgIcon
(
svg
,
painter
,
rect
)
if
icon
.
endswith
(
'.svg'
):
if
attributes
:
icon
=
writeSvg
(
icon
,
indexes
,
**
attributes
).
encode
()
drawSvgIcon
(
icon
,
painter
,
rect
)
else
:
icon
=
QIcon
(
icon
)
rect
=
QRectF
(
rect
).
toRect
()
painter
.
drawPixmap
(
rect
,
icon
.
pixmap
(
QRectF
(
rect
).
toRect
().
size
()))
class
FluentIcon
(
FluentIconBase
,
Enum
):
...
...
@@ -347,4 +384,4 @@ class Action(QAction):
self
.
fluentIcon
=
icon
icon
=
icon
.
icon
()
super
().
setIcon
(
icon
)
\ No newline at end of file
super
().
setIcon
(
icon
)
qfluentwidgets/components/widgets/label.py
浏览文件 @
407839f7
...
...
@@ -52,7 +52,8 @@ class FluentLabelBase(QLabel):
def
_init
(
self
):
self
.
setFont
(
self
.
getFont
())
self
.
setTextColor
()
qconfig
.
themeChanged
.
connect
(
lambda
:
self
.
setTextColor
())
qconfig
.
themeChanged
.
connect
(
lambda
:
self
.
setTextColor
(
self
.
lightColor
,
self
.
darkColor
))
return
self
def
getFont
(
self
):
...
...
@@ -73,6 +74,7 @@ class FluentLabelBase(QLabel):
color
=
self
.
darkColor
if
isDarkTheme
()
else
self
.
lightColor
palette
.
setColor
(
QPalette
.
WindowText
,
color
)
self
.
setPalette
(
palette
)
# self.setStyleSheet(f"QLabel{{color: {color.name()}}}")
class
CaptionLabel
(
FluentLabelBase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录