Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
d7df4155
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看板
提交
d7df4155
编写于
3月 14, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加更换主题的函数 `setTheme`
上级
2dc6bb7b
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
426 addition
and
226 deletion
+426
-226
docs/source/_static/gallery/navigation.gif
docs/source/_static/gallery/navigation.gif
+0
-0
docs/source/conf.py
docs/source/conf.py
+1
-1
docs/source/gallery.md
docs/source/gallery.md
+4
-1
examples/color_dialog/demo.py
examples/color_dialog/demo.py
+3
-1
examples/combo_box/demo.py
examples/combo_box/demo.py
+4
-2
examples/dialog/demo.py
examples/dialog/demo.py
+3
-1
examples/folder_list_dialog/demo.py
examples/folder_list_dialog/demo.py
+3
-1
examples/menu/demo.py
examples/menu/demo.py
+13
-11
examples/message_dialog/demo.py
examples/message_dialog/demo.py
+3
-1
examples/navigation/demo.py
examples/navigation/demo.py
+33
-23
examples/navigation/resource/dark/demo.qss
examples/navigation/resource/dark/demo.qss
+59
-0
examples/navigation/resource/light/demo.qss
examples/navigation/resource/light/demo.qss
+2
-1
examples/settings/demo.py
examples/settings/demo.py
+13
-48
examples/settings/resource/qss/dark/demo.qss
examples/settings/resource/qss/dark/demo.qss
+27
-0
examples/settings/resource/qss/light/demo.qss
examples/settings/resource/qss/light/demo.qss
+23
-0
examples/settings/setting_interface.py
examples/settings/setting_interface.py
+21
-20
qfluentwidgets/common/__init__.py
qfluentwidgets/common/__init__.py
+2
-2
qfluentwidgets/common/config.py
qfluentwidgets/common/config.py
+16
-2
qfluentwidgets/common/icon.py
qfluentwidgets/common/icon.py
+50
-25
qfluentwidgets/common/smooth_scroll.py
qfluentwidgets/common/smooth_scroll.py
+2
-2
qfluentwidgets/common/style_sheet.py
qfluentwidgets/common/style_sheet.py
+25
-2
qfluentwidgets/components/navigation/navigation_interface.py
qfluentwidgets/components/navigation/navigation_interface.py
+9
-6
qfluentwidgets/components/navigation/navigation_panel.py
qfluentwidgets/components/navigation/navigation_panel.py
+11
-7
qfluentwidgets/components/navigation/navigation_widget.py
qfluentwidgets/components/navigation/navigation_widget.py
+12
-9
qfluentwidgets/components/settings/expand_setting_card.py
qfluentwidgets/components/settings/expand_setting_card.py
+6
-4
qfluentwidgets/components/settings/folder_list_setting_card.py
...ntwidgets/components/settings/folder_list_setting_card.py
+12
-13
qfluentwidgets/components/settings/options_setting_card.py
qfluentwidgets/components/settings/options_setting_card.py
+7
-5
qfluentwidgets/components/settings/setting_card.py
qfluentwidgets/components/settings/setting_card.py
+36
-33
qfluentwidgets/components/widgets/combo_box.py
qfluentwidgets/components/widgets/combo_box.py
+3
-3
qfluentwidgets/components/widgets/icon_widget.py
qfluentwidgets/components/widgets/icon_widget.py
+21
-0
qfluentwidgets/components/widgets/menu.py
qfluentwidgets/components/widgets/menu.py
+2
-2
未找到文件。
docs/source/_static/gallery/navigation.gif
0 → 100644
浏览文件 @
d7df4155
248.7 KB
docs/source/conf.py
浏览文件 @
d7df4155
...
...
@@ -9,7 +9,7 @@
project
=
'PyQt-Fluent-Widgets'
copyright
=
'2023, zhiyiYo'
author
=
'zhiyiYo'
release
=
'v0.
1.1
'
release
=
'v0.
2.8
'
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
...
...
docs/source/gallery.md
浏览文件 @
d7df4155
...
...
@@ -18,6 +18,9 @@
### Win10 Style Message Dialog

### Navigation

### Flow Layout

...
...
@@ -37,4 +40,4 @@

### Tool Tip


\ No newline at end of file
examples/color_dialog/demo.py
浏览文件 @
d7df4155
...
...
@@ -4,7 +4,7 @@ import sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
from
qfluentwidgets
import
ColorPickerButton
from
qfluentwidgets
import
ColorPickerButton
,
setTheme
,
Theme
class
Demo
(
QWidget
):
...
...
@@ -16,6 +16,8 @@ class Demo(QWidget):
self
.
button
.
move
(
352
,
312
)
self
.
setStyleSheet
(
"Demo{background:white}"
)
# setTheme(Theme.DARK)
if
__name__
==
'__main__'
:
# enable dpi scale
...
...
examples/combo_box/demo.py
浏览文件 @
d7df4155
...
...
@@ -2,7 +2,7 @@
import
sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QHBoxLayout
from
qfluentwidgets
import
ComboBox
from
qfluentwidgets
import
ComboBox
,
setTheme
,
Theme
class
Demo
(
QWidget
):
...
...
@@ -14,9 +14,11 @@ class Demo(QWidget):
self
.
comboBox
.
setCurrentIndex
(
0
)
self
.
comboBox
.
currentTextChanged
.
connect
(
print
)
self
.
comboBox
.
move
(
200
,
200
)
self
.
resize
(
500
,
500
)
self
.
setStyleSheet
(
'Demo{background:white}'
)
# setTheme(Theme.DARK)
if
__name__
==
'__main__'
:
...
...
examples/dialog/demo.py
浏览文件 @
d7df4155
...
...
@@ -3,7 +3,7 @@ import sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QPushButton
from
qfluentwidgets
import
Dialog
from
qfluentwidgets
import
Dialog
,
setTheme
,
Theme
class
Window
(
QWidget
):
...
...
@@ -17,6 +17,8 @@ class Window(QWidget):
with
open
(
'resource/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
# setTheme(Theme.DARK)
def
showDialog
(
self
):
title
=
'Are you sure you want to delete the folder?'
content
=
"""If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted."""
...
...
examples/folder_list_dialog/demo.py
浏览文件 @
d7df4155
...
...
@@ -3,7 +3,7 @@ import sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QPushButton
from
qfluentwidgets
import
FolderListDialog
from
qfluentwidgets
import
FolderListDialog
,
setTheme
,
Theme
class
Window
(
QWidget
):
...
...
@@ -18,6 +18,8 @@ class Window(QWidget):
with
open
(
'resource/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
# setTheme(Theme.DARK)
def
showDialog
(
self
):
folder_paths
=
[
'D:/KuGou'
,
'C:/Users/shoko/Documents/Music'
]
title
=
'Build your collection from your local music files'
...
...
examples/menu/demo.py
浏览文件 @
d7df4155
...
...
@@ -2,8 +2,8 @@
import
sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QAction
,
QHBoxLayout
,
QLabel
from
qfluentwidgets
import
RoundMenu
from
qfluentwidgets
import
FluentIcon
Factory
as
FIF
from
qfluentwidgets
import
RoundMenu
,
setTheme
,
Theme
from
qfluentwidgets
import
FluentIcon
as
FIF
class
Demo
(
QWidget
):
...
...
@@ -18,26 +18,28 @@ class Demo(QWidget):
self
.
setStyleSheet
(
'Demo{background: white} QLabel{font-size: 20px}'
)
# setTheme(Theme.DARK)
def
contextMenuEvent
(
self
,
e
):
menu
=
RoundMenu
(
parent
=
self
)
# add actions
menu
.
addAction
(
QAction
(
FIF
.
icon
(
FIF
.
COPY
),
'Copy'
))
menu
.
addAction
(
QAction
(
FIF
.
icon
(
FIF
.
CUT
),
'Cut'
))
menu
.
addAction
(
QAction
(
FIF
.
COPY
.
icon
(
),
'Copy'
))
menu
.
addAction
(
QAction
(
FIF
.
CUT
.
icon
(
),
'Cut'
))
# add sub menu
submenu
=
RoundMenu
(
"Add to"
,
self
)
submenu
.
setIcon
(
FIF
.
icon
(
FIF
.
ADD
))
submenu
.
setIcon
(
FIF
.
ADD
.
icon
(
))
submenu
.
addActions
([
QAction
(
FIF
.
icon
(
FIF
.
VIDEO
),
'Video'
),
QAction
(
FIF
.
icon
(
FIF
.
MUSIC
),
'Music'
),
QAction
(
FIF
.
VIDEO
.
icon
(
),
'Video'
),
QAction
(
FIF
.
MUSIC
.
icon
(
),
'Music'
),
])
menu
.
addMenu
(
submenu
)
# add actions
menu
.
addActions
([
QAction
(
FIF
.
icon
(
FIF
.
PASTE
),
'Paste'
),
QAction
(
FIF
.
icon
(
FIF
.
CANCEL
),
'Undo'
)
QAction
(
FIF
.
PASTE
.
icon
(
),
'Paste'
),
QAction
(
FIF
.
CANCEL
.
icon
(
),
'Undo'
)
])
# add separator
...
...
@@ -46,10 +48,10 @@ class Demo(QWidget):
# insert actions
menu
.
insertAction
(
menu
.
menuActions
()[
-
1
],
QAction
(
FIF
.
icon
(
FIF
.
SETTING
),
'Settings'
))
menu
.
menuActions
()[
-
1
],
QAction
(
FIF
.
SETTING
.
icon
(
),
'Settings'
))
menu
.
insertActions
(
menu
.
menuActions
()[
-
1
],
[
QAction
(
FIF
.
icon
(
FIF
.
HELP
),
'Help'
),
QAction
(
FIF
.
icon
(
FIF
.
FEEDBACK
),
'Feedback'
)]
[
QAction
(
FIF
.
HELP
.
icon
(),
'Help'
),
QAction
(
FIF
.
FEEDBACK
.
icon
(
),
'Feedback'
)]
)
# show menu
...
...
examples/message_dialog/demo.py
浏览文件 @
d7df4155
...
...
@@ -3,7 +3,7 @@ import sys
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QPushButton
from
qfluentwidgets
import
MessageDialog
,
MessageBox
from
qfluentwidgets
import
MessageDialog
,
MessageBox
,
setTheme
,
Theme
class
Window
(
QWidget
):
...
...
@@ -17,6 +17,8 @@ class Window(QWidget):
with
open
(
'resource/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
# setTheme(Theme.DARK)
def
showDialog
(
self
):
title
=
'Are you sure you want to delete the folder?'
content
=
"""If you delete the "Music" folder from the list, the folder will no longer appear in the list, but will not be deleted."""
...
...
examples/navigation/demo.py
浏览文件 @
d7df4155
...
...
@@ -4,9 +4,9 @@ from PyQt5.QtCore import Qt, QRect
from
PyQt5.QtGui
import
QIcon
,
QPainter
,
QImage
,
QBrush
,
QColor
,
QFont
from
PyQt5.QtWidgets
import
QApplication
,
QFrame
,
QStackedWidget
,
QHBoxLayout
,
QLabel
from
qfluentwidgets
import
NavigationInterface
,
NavigationItemPostion
,
NavigationWidget
,
MessageBox
from
qfluentwidgets
import
FluentIconFactory
as
FIF
from
qfluentwidgets
import
(
NavigationInterface
,
NavigationItemPostion
,
NavigationWidget
,
MessageBox
,
isDarkTheme
,
setTheme
,
Theme
)
from
qfluentwidgets
import
FluentIcon
as
FIF
from
qframelesswindow
import
FramelessWindow
,
StandardTitleBar
...
...
@@ -40,14 +40,7 @@ class AvatarWidget(NavigationWidget):
painter
.
setOpacity
(
0.7
)
# draw background
if
self
.
isSelected
:
painter
.
setBrush
(
QColor
(
0
,
0
,
0
,
6
if
self
.
isEnter
else
10
))
painter
.
drawRoundedRect
(
self
.
rect
(),
5
,
5
)
# draw indicator
painter
.
setBrush
(
QColor
(
0
,
153
,
188
))
painter
.
drawRoundedRect
(
0
,
10
,
3
,
16
,
1.5
,
1.5
)
elif
self
.
isEnter
:
if
self
.
isEnter
:
painter
.
setBrush
(
QColor
(
0
,
0
,
0
,
10
))
painter
.
drawRoundedRect
(
self
.
rect
(),
5
,
5
)
...
...
@@ -58,7 +51,7 @@ class AvatarWidget(NavigationWidget):
painter
.
translate
(
-
8
,
-
6
)
if
not
self
.
isCompacted
:
painter
.
setPen
(
Qt
.
black
)
painter
.
setPen
(
Qt
.
white
if
isDarkTheme
()
else
Qt
.
black
)
font
=
QFont
(
'Segoe UI'
)
font
.
setPixelSize
(
14
)
painter
.
setFont
(
font
)
...
...
@@ -71,8 +64,11 @@ class Window(FramelessWindow):
super
().
__init__
()
self
.
setTitleBar
(
StandardTitleBar
(
self
))
# use dark theme mode
setTheme
(
Theme
.
DARK
)
self
.
hBoxLayout
=
QHBoxLayout
(
self
)
self
.
navigationInterface
=
NavigationInterface
(
self
,
True
)
self
.
navigationInterface
=
NavigationInterface
(
self
,
showMenuButton
=
True
)
self
.
stackWidget
=
QStackedWidget
(
self
)
# create sub interface
...
...
@@ -89,28 +85,36 @@ class Window(FramelessWindow):
self
.
stackWidget
.
addWidget
(
self
.
settingInterface
)
# initialize layout
self
.
initLayout
()
# add items to navigation interface
self
.
initNavigation
()
self
.
initWindow
()
def
initLayout
(
self
):
self
.
hBoxLayout
.
setSpacing
(
0
)
self
.
hBoxLayout
.
setContentsMargins
(
0
,
self
.
titleBar
.
height
(),
0
,
0
)
self
.
hBoxLayout
.
addWidget
(
self
.
navigationInterface
)
self
.
hBoxLayout
.
addWidget
(
self
.
stackWidget
)
self
.
hBoxLayout
.
setStretchFactor
(
self
.
stackWidget
,
1
)
# add items to navigation interface
def
initNavigation
(
self
):
self
.
navigationInterface
.
addItem
(
routeKey
=
self
.
searchInterface
.
objectName
(),
icon
Path
=
FIF
.
path
(
FIF
.
SEARCH
)
,
icon
=
FIF
.
SEARCH
,
text
=
'Search'
,
onClick
=
lambda
:
self
.
switchTo
(
self
.
searchInterface
)
)
self
.
navigationInterface
.
addItem
(
routeKey
=
self
.
musicInterface
.
objectName
(),
icon
Path
=
FIF
.
path
(
FIF
.
MUSIC
)
,
icon
=
FIF
.
MUSIC
,
text
=
'Music library'
,
onClick
=
lambda
:
self
.
switchTo
(
self
.
musicInterface
)
)
self
.
navigationInterface
.
addItem
(
routeKey
=
self
.
navigationInterface
.
objectName
(),
icon
Path
=
FIF
.
path
(
FIF
.
VIDEO
)
,
icon
=
FIF
.
VIDEO
,
text
=
'Video library'
,
onClick
=
lambda
:
self
.
switchTo
(
self
.
videoInterface
)
)
...
...
@@ -120,7 +124,7 @@ class Window(FramelessWindow):
# add navigation items to scroll area
self
.
navigationInterface
.
addItem
(
routeKey
=
'folder'
,
icon
Path
=
FIF
.
path
(
FIF
.
FOLDER
)
,
icon
=
FIF
.
FOLDER
,
text
=
'Folder library'
,
onClick
=
lambda
:
self
.
switchTo
(
self
.
folderInterface
),
position
=
NavigationItemPostion
.
SCROLL
...
...
@@ -128,7 +132,7 @@ class Window(FramelessWindow):
# for i in range(1, 21):
# self.navigationInterface.addItem(
# f'folder{i}',
# FIF.
path(FIF.FOLDER)
,
# FIF.
FOLDER
,
# f'Folder {i}',
# lambda: print('Folder clicked'),
# position=NavigationItemPostion.SCROLL
...
...
@@ -144,7 +148,7 @@ class Window(FramelessWindow):
self
.
navigationInterface
.
addItem
(
routeKey
=
'setting'
,
icon
Path
=
FIF
.
path
(
FIF
.
SETTING
)
,
icon
=
FIF
.
SETTING
,
text
=
'Settings'
,
onClick
=
lambda
:
self
.
switchTo
(
self
.
settingInterface
),
position
=
NavigationItemPostion
.
BOTTOM
...
...
@@ -153,17 +157,23 @@ class Window(FramelessWindow):
self
.
stackWidget
.
currentChanged
.
connect
(
self
.
onCurrentInterfaceChanged
)
self
.
stackWidget
.
setCurrentIndex
(
1
)
with
open
(
'resource/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
def
initWindow
(
self
):
self
.
resize
(
900
,
700
)
self
.
setWindowIcon
(
QIcon
(
'resource/logo.png'
))
self
.
setWindowTitle
(
'PyQt-Fluent-Widgets'
)
self
.
titleBar
.
setAttribute
(
Qt
.
WA_StyledBackground
)
desktop
=
QApplication
.
desktop
().
availableGeometry
()
w
,
h
=
desktop
.
width
(),
desktop
.
height
()
self
.
move
(
w
//
2
-
self
.
width
()
//
2
,
h
//
2
-
self
.
height
()
//
2
)
self
.
setQss
()
def
setQss
(
self
):
color
=
'dark'
if
isDarkTheme
()
else
'light'
with
open
(
f
'resource/
{
color
}
/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
def
switchTo
(
self
,
widget
):
self
.
stackWidget
.
setCurrentWidget
(
widget
)
...
...
examples/navigation/resource/dark/demo.qss
0 → 100644
浏览文件 @
d7df4155
Widget > QLabel {
font: 24px 'Segoe UI', 'Microsoft YaHei';
}
Widget {
border: 1px solid rgb(229, 229, 229);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb(249, 249, 249);
}
Window {
background-color: rgb(243, 243, 243);
}
Window {
background-color: rgb(32, 32, 32);
}
StandardTitleBar {
background-color: rgb(32, 32, 32);
}
StandardTitleBar > QLabel,
Widget > QLabel {
color: white;
}
Widget {
border: 1px solid rgb(29, 29, 29);
background-color: rgb(39, 39, 39);
}
MinimizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
MaximizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
CloseButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
}
examples/navigation/resource/demo.qss
→
examples/navigation/resource/
light/
demo.qss
浏览文件 @
d7df4155
...
...
@@ -12,4 +12,5 @@ Widget {
Window {
background-color: rgb(243, 243, 243);
}
\ No newline at end of file
}
examples/settings/demo.py
浏览文件 @
d7df4155
# coding:utf-8
import
os
import
sys
from
PyQt5.QtCore
import
Qt
,
QLocale
,
QTranslator
from
PyQt5.QtGui
import
QIcon
,
QColor
from
PyQt5.QtWidgets
import
QApplication
,
Q
Label
,
Q
HBoxLayout
from
PyQt5.QtGui
import
QIcon
from
PyQt5.QtWidgets
import
QApplication
,
QHBoxLayout
from
qframelesswindow
import
FramelessWindow
,
TitleBar
from
qframelesswindow.titlebar
import
TitleBarButton
from
qframelesswindow
import
FramelessWindow
,
StandardTitleBar
from
qfluentwidgets
import
isDarkTheme
from
setting_interface
import
SettingInterface
from
config
import
cfg
,
Language
class
CustomTitleBar
(
TitleBar
):
""" Custom title bar """
def
__init__
(
self
,
parent
):
super
().
__init__
(
parent
)
# add window icon
self
.
iconLabel
=
QLabel
(
self
)
self
.
iconLabel
.
setFixedSize
(
20
,
20
)
self
.
hBoxLayout
.
insertSpacing
(
0
,
8
)
self
.
hBoxLayout
.
insertWidget
(
1
,
self
.
iconLabel
,
0
,
Qt
.
AlignLeft
)
self
.
window
().
windowIconChanged
.
connect
(
self
.
setIcon
)
# add title label
self
.
titleLabel
=
QLabel
(
self
)
self
.
hBoxLayout
.
insertWidget
(
2
,
self
.
titleLabel
,
0
,
Qt
.
AlignLeft
)
self
.
titleLabel
.
setStyleSheet
(
f
"""
QLabel{{
background: transparent;
font: 13px 'Segoe UI';
padding: 0 4px;
color:
{
'white'
if
isDarkTheme
()
else
'black'
}
}}
"""
)
self
.
window
().
windowTitleChanged
.
connect
(
self
.
setTitle
)
# customize title bar button
if
isDarkTheme
():
for
button
in
(
self
.
findChildren
(
TitleBarButton
)):
button
.
setNormalColor
(
Qt
.
white
)
button
.
setHoverColor
(
Qt
.
white
)
button
.
setPressedColor
(
Qt
.
white
)
if
button
is
not
self
.
closeBtn
:
button
.
setHoverBackgroundColor
(
QColor
(
255
,
255
,
255
,
26
))
button
.
setPressedBackgroundColor
(
QColor
(
255
,
255
,
255
,
51
))
def
setTitle
(
self
,
title
):
self
.
titleLabel
.
setText
(
title
)
self
.
titleLabel
.
adjustSize
()
def
setIcon
(
self
,
icon
):
self
.
iconLabel
.
setPixmap
(
icon
.
pixmap
(
20
,
20
))
class
Window
(
FramelessWindow
):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
# change the default title bar if you like
self
.
setTitleBar
(
CustomTitleBar
(
self
))
self
.
setTitleBar
(
StandardTitleBar
(
self
))
self
.
hBoxLayout
=
QHBoxLayout
(
self
)
self
.
settingInterface
=
SettingInterface
(
self
)
...
...
@@ -77,6 +34,14 @@ class Window(FramelessWindow):
self
.
titleBar
.
raise_
()
self
.
setQss
()
cfg
.
themeChanged
.
connect
(
self
.
setQss
)
def
setQss
(
self
):
theme
=
'dark'
if
isDarkTheme
()
else
'light'
with
open
(
f
'resource/qss/
{
theme
}
/demo.qss'
,
encoding
=
'utf-8'
)
as
f
:
self
.
setStyleSheet
(
f
.
read
())
if
__name__
==
'__main__'
:
# enable dpi scale
...
...
examples/settings/resource/qss/dark/demo.qss
0 → 100644
浏览文件 @
d7df4155
MinimizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
MaximizeButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgba(255, 255, 255, 26);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgba(255, 255, 255, 51)
}
CloseButton {
qproperty-normalColor: white;
qproperty-normalBackgroundColor: transparent;
}
StandardTitleBar > QLabel {
color: white;
}
\ No newline at end of file
examples/settings/resource/qss/light/demo.qss
0 → 100644
浏览文件 @
d7df4155
MinimizeButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: black;
qproperty-hoverBackgroundColor: rgba(0, 0, 0, 26);
qproperty-pressedColor: black;
qproperty-pressedBackgroundColor: rgba(0, 0, 0, 51)
}
MaximizeButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
qproperty-hoverColor: black;
qproperty-hoverBackgroundColor: rgba(0, 0, 0, 26);
qproperty-pressedColor: black;
qproperty-pressedBackgroundColor: rgba(0, 0, 0, 51)
}
CloseButton {
qproperty-normalColor: black;
qproperty-normalBackgroundColor: transparent;
}
\ No newline at end of file
examples/settings/setting_interface.py
浏览文件 @
d7df4155
...
...
@@ -3,8 +3,8 @@ from config import cfg, HELP_URL, FEEDBACK_URL, AUTHOR, VERSION, YEAR
from
qfluentwidgets
import
(
SettingCardGroup
,
SwitchSettingCard
,
FolderListSettingCard
,
OptionsSettingCard
,
RangeSettingCard
,
PushSettingCard
,
ColorSettingCard
,
HyperlinkCard
,
PrimaryPushSettingCard
,
ScrollArea
,
ComboBoxSettingCard
,
ExpandLayout
,
setStyleSheet
,
ToastToolTip
)
from
qfluentwidgets
import
FluentIcon
Factory
as
FIF
ComboBoxSettingCard
,
ExpandLayout
,
setStyleSheet
,
ToastToolTip
,
setTheme
)
from
qfluentwidgets
import
FluentIcon
as
FIF
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QUrl
,
QStandardPaths
from
PyQt5.QtGui
import
QDesktopServices
from
PyQt5.QtWidgets
import
QWidget
,
QLabel
,
QFontDialog
,
QFileDialog
...
...
@@ -38,7 +38,7 @@ class SettingInterface(ScrollArea):
)
self
.
downloadFolderCard
=
PushSettingCard
(
self
.
tr
(
'Choose folder'
),
FIF
.
path
(
FIF
.
DOWNLOAD
)
,
FIF
.
DOWNLOAD
,
self
.
tr
(
"Download directory"
),
cfg
.
get
(
cfg
.
downloadFolder
),
self
.
musicInThisPCGroup
...
...
@@ -47,7 +47,7 @@ class SettingInterface(ScrollArea):
# personalization
self
.
personalGroup
=
SettingCardGroup
(
self
.
tr
(
'Personalization'
),
self
.
scrollWidget
)
self
.
enableAcrylicCard
=
SwitchSettingCard
(
FIF
.
path
(
FIF
.
TRANSPARENT
)
,
FIF
.
TRANSPARENT
,
self
.
tr
(
"Use Acrylic effect"
),
self
.
tr
(
"Acrylic effect has better visual experience, but it may cause the window to become stuck"
),
configItem
=
cfg
.
enableAcrylicBackground
,
...
...
@@ -55,7 +55,7 @@ class SettingInterface(ScrollArea):
)
self
.
themeCard
=
OptionsSettingCard
(
cfg
.
themeMode
,
FIF
.
path
(
FIF
.
BRUSH
)
,
FIF
.
BRUSH
,
self
.
tr
(
'Application theme'
),
self
.
tr
(
"Change the appearance of your application"
),
texts
=
[
...
...
@@ -66,7 +66,7 @@ class SettingInterface(ScrollArea):
)
self
.
zoomCard
=
OptionsSettingCard
(
cfg
.
dpiScale
,
FIF
.
path
(
FIF
.
ZOOM
)
,
FIF
.
ZOOM
,
self
.
tr
(
"Interface zoom"
),
self
.
tr
(
"Change the size of widgets and fonts"
),
texts
=
[
...
...
@@ -77,7 +77,7 @@ class SettingInterface(ScrollArea):
)
self
.
languageCard
=
ComboBoxSettingCard
(
cfg
.
language
,
FIF
.
path
(
FIF
.
LANGUAGE
)
,
FIF
.
LANGUAGE
,
self
.
tr
(
'Language'
),
self
.
tr
(
'Set your preferred language for UI'
),
texts
=
[
'简体中文'
,
'繁體中文'
,
'English'
,
self
.
tr
(
'Use system setting'
)],
...
...
@@ -88,13 +88,13 @@ class SettingInterface(ScrollArea):
self
.
onlineMusicGroup
=
SettingCardGroup
(
self
.
tr
(
'Online Music'
),
self
.
scrollWidget
)
self
.
onlinePageSizeCard
=
RangeSettingCard
(
cfg
.
onlinePageSize
,
FIF
.
path
(
FIF
.
SEARCH
)
,
FIF
.
SEARCH
,
self
.
tr
(
"Number of online music displayed on each page"
),
parent
=
self
.
onlineMusicGroup
)
self
.
onlineMusicQualityCard
=
OptionsSettingCard
(
cfg
.
onlineSongQuality
,
FIF
.
path
(
FIF
.
MUSIC
)
,
FIF
.
MUSIC
,
self
.
tr
(
'Online music quality'
),
texts
=
[
self
.
tr
(
'Standard quality'
),
self
.
tr
(
'High quality'
),
...
...
@@ -104,7 +104,7 @@ class SettingInterface(ScrollArea):
)
self
.
onlineMvQualityCard
=
OptionsSettingCard
(
cfg
.
onlineMvQuality
,
FIF
.
path
(
FIF
.
VIDEO
)
,
FIF
.
VIDEO
,
self
.
tr
(
'Online MV quality'
),
texts
=
[
self
.
tr
(
'Full HD'
),
self
.
tr
(
'HD'
),
...
...
@@ -117,31 +117,31 @@ class SettingInterface(ScrollArea):
self
.
deskLyricGroup
=
SettingCardGroup
(
self
.
tr
(
'Desktop Lyric'
),
self
.
scrollWidget
)
self
.
deskLyricFontCard
=
PushSettingCard
(
self
.
tr
(
'Choose font'
),
FIF
.
path
(
FIF
.
FONT
)
,
FIF
.
FONT
,
self
.
tr
(
'Font'
),
parent
=
self
.
deskLyricGroup
)
self
.
deskLyricHighlightColorCard
=
ColorSettingCard
(
cfg
.
deskLyricHighlightColor
,
FIF
.
path
(
FIF
.
PALETTE
)
,
FIF
.
PALETTE
,
self
.
tr
(
'Foreground color'
),
parent
=
self
.
deskLyricGroup
)
self
.
deskLyricStrokeColorCard
=
ColorSettingCard
(
cfg
.
deskLyricStrokeColor
,
FIF
.
path
(
FIF
.
PENCIL_INK
)
,
FIF
.
PENCIL_INK
,
self
.
tr
(
'Stroke color'
),
parent
=
self
.
deskLyricGroup
)
self
.
deskLyricStrokeSizeCard
=
RangeSettingCard
(
cfg
.
deskLyricStrokeSize
,
FIF
.
path
(
FIF
.
FLUORESCENT_PEN
)
,
FIF
.
FLUORESCENT_PEN
,
self
.
tr
(
'Stroke size'
),
parent
=
self
.
deskLyricGroup
)
self
.
deskLyricAlignmentCard
=
OptionsSettingCard
(
cfg
.
deskLyricAlignment
,
FIF
.
path
(
FIF
.
ALIGNMENT
)
,
FIF
.
ALIGNMENT
,
self
.
tr
(
'Alignment'
),
texts
=
[
self
.
tr
(
'Center aligned'
),
self
.
tr
(
'Left aligned'
),
...
...
@@ -153,7 +153,7 @@ class SettingInterface(ScrollArea):
# main panel
self
.
mainPanelGroup
=
SettingCardGroup
(
self
.
tr
(
'Main Panel'
),
self
.
scrollWidget
)
self
.
minimizeToTrayCard
=
SwitchSettingCard
(
FIF
.
path
(
FIF
.
MINIMIZE
)
,
FIF
.
MINIMIZE
,
self
.
tr
(
'Minimize to tray after closing'
),
self
.
tr
(
'PyQt-Fluent-Widgets will continue to run in the background'
),
configItem
=
cfg
.
minimizeToTray
,
...
...
@@ -163,7 +163,7 @@ class SettingInterface(ScrollArea):
# update software
self
.
updateSoftwareGroup
=
SettingCardGroup
(
self
.
tr
(
"Software update"
),
self
.
scrollWidget
)
self
.
updateOnStartUpCard
=
SwitchSettingCard
(
FIF
.
path
(
FIF
.
UPDATE
)
,
FIF
.
UPDATE
,
self
.
tr
(
'Check for updates when the application starts'
),
self
.
tr
(
'The new version will be more stable and have more features'
),
configItem
=
cfg
.
checkUpdateAtStartUp
,
...
...
@@ -175,21 +175,21 @@ class SettingInterface(ScrollArea):
self
.
helpCard
=
HyperlinkCard
(
HELP_URL
,
self
.
tr
(
'Open help page'
),
FIF
.
path
(
FIF
.
HELP
)
,
FIF
.
HELP
,
self
.
tr
(
'Help'
),
self
.
tr
(
'Discover new features and learn useful tips about PyQt-Fluent-Widgets'
),
self
.
aboutGroup
)
self
.
feedbackCard
=
PrimaryPushSettingCard
(
self
.
tr
(
'Provide feedback'
),
FIF
.
path
(
FIF
.
FEEDBACK
)
,
FIF
.
FEEDBACK
,
self
.
tr
(
'Provide feedback'
),
self
.
tr
(
'Help us improve PyQt-Fluent-Widgets by providing feedback'
),
self
.
aboutGroup
)
self
.
aboutCard
=
PrimaryPushSettingCard
(
self
.
tr
(
'Check update'
),
FIF
.
path
(
FIF
.
INFO
)
,
FIF
.
INFO
,
self
.
tr
(
'About'
),
'© '
+
self
.
tr
(
'Copyright'
)
+
f
"
{
YEAR
}
,
{
AUTHOR
}
. "
+
self
.
tr
(
'Version'
)
+
f
"
{
VERSION
[
1
:]
}
"
,
...
...
@@ -283,6 +283,7 @@ class SettingInterface(ScrollArea):
def
__connectSignalToSlot
(
self
):
""" connect signal to slot """
cfg
.
appRestartSig
.
connect
(
self
.
__showRestartTooltip
)
cfg
.
themeChanged
.
connect
(
setTheme
)
# music in the pc
self
.
musicFolderCard
.
folderChanged
.
connect
(
...
...
qfluentwidgets/common/__init__.py
浏览文件 @
d7df4155
from
.config
import
*
from
.auto_wrap
import
TextWrap
from
.icon
import
Icon
,
getIconColor
,
drawSvgIcon
,
FluentIcon
Factory
,
drawIcon
from
.style_sheet
import
setStyleSheet
,
getStyleSheet
from
.icon
import
Icon
,
getIconColor
,
drawSvgIcon
,
FluentIcon
,
drawIcon
from
.style_sheet
import
setStyleSheet
,
getStyleSheet
,
setTheme
from
.smooth_scroll
import
SmoothScroll
,
SmoothMode
\ No newline at end of file
qfluentwidgets/common/config.py
浏览文件 @
d7df4155
...
...
@@ -2,11 +2,12 @@
import
json
from
enum
import
Enum
from
pathlib
import
Path
from
typing
import
Iterable
,
List
,
Union
from
typing
import
List
import
darkdetect
from
PyQt5.QtCore
import
QObject
,
pyqtSignal
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtWidgets
import
qApp
from
.exception_handler
import
exceptionHandler
...
...
@@ -249,9 +250,10 @@ class QConfig(QObject):
""" Config of app """
appRestartSig
=
pyqtSignal
()
themeChanged
=
pyqtSignal
(
Theme
)
themeMode
=
OptionsConfigItem
(
"MainWindow"
,
"ThemeMode"
,
Theme
.
AUTO
,
OptionsValidator
(
Theme
),
EnumSerializer
(
Theme
)
,
restart
=
True
)
"MainWindow"
,
"ThemeMode"
,
Theme
.
AUTO
,
OptionsValidator
(
Theme
),
EnumSerializer
(
Theme
))
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -274,6 +276,9 @@ class QConfig(QObject):
if
item
.
restart
:
self
.
_cfg
.
appRestartSig
.
emit
()
if
item
is
self
.
_cfg
.
themeMode
:
self
.
_cfg
.
themeChanged
.
emit
(
value
)
def
toDict
(
self
,
serialize
=
True
):
""" convert config items to `dict` """
items
=
{}
...
...
@@ -354,6 +359,15 @@ class QConfig(QObject):
""" get theme mode, can be `Theme.Light` or `Theme.Dark` """
return
self
.
_cfg
.
_theme
@
theme
.
setter
def
theme
(
self
,
t
):
""" chaneg the theme without modifying the config file """
if
t
==
Theme
.
AUTO
:
t
=
darkdetect
.
theme
()
t
=
Theme
(
t
)
if
t
else
Theme
.
LIGHT
self
.
_cfg
.
_theme
=
t
qconfig
=
QConfig
()
...
...
qfluentwidgets/common/icon.py
浏览文件 @
d7df4155
# coding:utf-8
from
enum
import
Enum
from
PyQt5.QtCore
import
QPoint
,
QRect
,
QRectF
,
Qt
from
PyQt5.QtGui
import
QIcon
,
QIconEngine
,
QImage
,
QPainter
,
QPixmap
from
PyQt5.QtSvg
import
QSvgRenderer
from
.config
import
isDarkTheme
from
.config
import
isDarkTheme
,
Theme
class
IconEngine
(
QIconEngine
):
...
...
@@ -68,13 +70,13 @@ def drawSvgIcon(iconPath, painter, rect):
renderer
.
render
(
painter
,
QRectF
(
rect
))
def
drawIcon
(
icon
Path
,
p
ainter
,
rect
):
def
drawIcon
(
icon
,
painter
:
QP
ainter
,
rect
):
""" draw icon
Parameters
----------
icon
Path: str
the
path of svg ico
n
icon
: `str` | `QIcon` | `FluentIcon`
the
icon to be draw
n
painter: QPainter
painter
...
...
@@ -82,16 +84,16 @@ def drawIcon(iconPath, painter, rect):
rect: QRect | QRectF
the rect to render icon
"""
if
not
iconPath
.
lower
().
endswith
(
'svg'
):
image
=
QImage
(
iconPath
).
scaled
(
rect
.
width
(),
rect
.
height
(),
Qt
.
KeepAspectRatio
,
Qt
.
SmoothTransformation
)
painter
.
drawImage
(
rect
,
image
)
if
isinstance
(
icon
,
FluentIcon
):
icon
.
render
(
painter
,
rect
)
else
:
drawSvgIcon
(
iconPath
,
painter
,
rect
)
icon
=
QIcon
(
icon
)
image
=
icon
.
pixmap
(
rect
.
width
(),
rect
.
height
())
painter
.
drawPixmap
(
rect
,
image
)
class
FluentIcon
Factory
:
""" Fluent icon
factory
"""
class
FluentIcon
(
Enum
)
:
""" Fluent icon """
WEB
=
"Web"
CUT
=
"Cut"
...
...
@@ -131,29 +133,52 @@ class FluentIconFactory:
BACKGROUND_FILL
=
"BackgroundColor"
FLUORESCENT_PEN
=
"FluorescentPen"
@
staticmethod
def
path
(
iconType
):
""" get the path of icon """
return
f
':/qfluentwidgets/images/icons/
{
iconType
}
_
{
getIconColor
()
}
.svg'
def
path
(
self
,
theme
=
Theme
.
AUTO
):
""" get the path of icon
@
classmethod
def
icon
(
cls
,
iconType
):
""" create an fluent icon """
return
QIcon
(
cls
.
path
(
iconType
))
Parameters
----------
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
if
theme
==
Theme
.
AUTO
:
c
=
getIconColor
()
else
:
c
=
"white"
if
theme
==
Theme
.
DARK
else
"black"
@
classmethod
def
render
(
cls
,
iconType
,
painter
,
rect
):
""" draw svg icon
return
f
':/qfluentwidgets/images/icons/
{
self
.
value
}
_
{
c
}
.svg'
def
icon
(
self
,
theme
=
Theme
.
AUTO
):
""" create an fluent icon
Parameters
----------
iconType: str
fluent icon type
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
return
QIcon
(
self
.
path
(
theme
))
def
render
(
self
,
painter
,
rect
,
theme
=
Theme
.
AUTO
):
""" draw svg icon
Parameters
----------
painter: QPainter
painter
rect: QRect | QRectF
the rect to render icon
theme: Theme
the theme of icon
* `Theme.Light`: black icon
* `Theme.DARK`: white icon
* `Theme.AUTO`: icon color depends on `config.theme`
"""
drawSvgIcon
(
cls
.
path
(
iconType
),
painter
,
rect
)
\ No newline at end of file
drawSvgIcon
(
self
.
path
(
theme
),
painter
,
rect
)
\ No newline at end of file
qfluentwidgets/common/smooth_scroll.py
浏览文件 @
d7df4155
...
...
@@ -5,7 +5,7 @@ from math import cos, pi
from
PyQt5.QtCore
import
QDateTime
,
Qt
,
QTimer
,
QPoint
from
PyQt5.QtGui
import
QWheelEvent
from
PyQt5.QtWidgets
import
QApplication
,
QScrollArea
from
PyQt5.QtWidgets
import
QApplication
,
QScrollArea
,
QAbstractScrollArea
class
SmoothScroll
:
...
...
@@ -41,7 +41,7 @@ class SmoothScroll:
def
wheelEvent
(
self
,
e
):
if
self
.
smoothMode
==
SmoothMode
.
NO_SMOOTH
:
self
.
widget
.
wheelEvent
(
e
)
QAbstractScrollArea
.
wheelEvent
(
self
.
widget
,
e
)
return
# push current time to queque
...
...
qfluentwidgets/common/style_sheet.py
浏览文件 @
d7df4155
# coding:utf-8
from
.config
import
qconfig
,
Theme
import
weakref
import
darkdetect
from
PyQt5.QtCore
import
QFile
from
.config
import
qconfig
,
Theme
fluentWidgets
=
weakref
.
WeakKeyDictionary
()
def
getStyleSheet
(
file
,
theme
=
Theme
.
AUTO
):
""" get style sheet
...
...
@@ -36,4 +43,20 @@ def setStyleSheet(widget, file, theme=Theme.AUTO):
theme: Theme
the theme of style sheet
"""
widget
.
setStyleSheet
(
getStyleSheet
(
file
,
theme
))
\ No newline at end of file
# register widget
if
widget
not
in
fluentWidgets
:
fluentWidgets
[
widget
]
=
file
widget
.
setStyleSheet
(
getStyleSheet
(
file
,
theme
))
def
setTheme
(
theme
:
Theme
):
""" set the theme of application """
if
theme
==
Theme
.
AUTO
:
theme
=
darkdetect
.
theme
()
qconfig
.
theme
=
Theme
(
theme
)
if
theme
else
Theme
.
LIGHT
else
:
qconfig
.
theme
=
theme
for
widget
,
file
in
fluentWidgets
.
items
():
setStyleSheet
(
widget
,
file
,
qconfig
.
theme
)
\ No newline at end of file
qfluentwidgets/components/navigation/navigation_interface.py
浏览文件 @
d7df4155
# coding:utf-8
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QEvent
from
PyQt5.QtGui
import
QResizeEvent
from
typing
import
Union
from
PyQt5.QtCore
import
Qt
,
QEvent
from
PyQt5.QtGui
import
QResizeEvent
,
QIcon
from
PyQt5.QtWidgets
import
QWidget
from
.navigation_panel
import
NavigationPanel
,
NavigationItemPostion
,
NavigationWidget
,
NavigationDisplayMode
from
...common.style_sheet
import
setStyleSheet
from
...common.icon
import
FluentIcon
class
NavigationInterface
(
QWidget
):
...
...
@@ -30,7 +33,7 @@ class NavigationInterface(QWidget):
self
.
setAttribute
(
Qt
.
WA_StyledBackground
)
setStyleSheet
(
self
,
'navigation_interface'
)
def
addItem
(
self
,
routeKey
:
str
,
icon
Path
:
str
,
text
:
str
,
onClick
,
selectable
=
True
,
position
=
NavigationItemPostion
.
TOP
):
def
addItem
(
self
,
routeKey
:
str
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
text
:
str
,
onClick
,
selectable
=
True
,
position
=
NavigationItemPostion
.
TOP
):
""" add navigation item
Parameters
...
...
@@ -38,8 +41,8 @@ class NavigationInterface(QWidget):
routKey: str
the unique name of item
icon
Path: str
the
svg icon path
of navigation item
icon
: str | QIcon | FluentIcon
the
icon
of navigation item
text: str
the text of navigation item
...
...
@@ -53,7 +56,7 @@ class NavigationInterface(QWidget):
selectable: bool
whether the item is selectable
"""
self
.
panel
.
addItem
(
routeKey
,
icon
Path
,
text
,
onClick
,
selectable
,
position
)
self
.
panel
.
addItem
(
routeKey
,
icon
,
text
,
onClick
,
selectable
,
position
)
def
addWidget
(
self
,
routeKey
:
str
,
widget
:
NavigationWidget
,
onClick
,
position
=
NavigationItemPostion
.
TOP
):
""" add custom widget
...
...
qfluentwidgets/components/navigation/navigation_panel.py
浏览文件 @
d7df4155
# coding:utf-8
from
enum
import
Enum
from
typing
import
Dict
from
typing
import
Dict
,
Union
from
PyQt5.QtCore
import
Qt
,
QPropertyAnimation
,
QRect
,
QSize
,
QEvent
,
QEasingCurve
from
PyQt5.QtGui
import
QResizeEvent
from
PyQt5.QtWidgets
import
QWidget
,
QVBoxLayout
,
QFrame
,
QApplication
from
PyQt5.QtGui
import
QResizeEvent
,
QIcon
from
PyQt5.QtWidgets
import
QWidget
,
QVBoxLayout
,
QFrame
from
.navigation_widget
import
NavigationButton
,
MenuButton
,
NavigationWidget
,
NavigationSeparator
from
..widgets.scroll_area
import
ScrollArea
from
...common.style_sheet
import
setStyleSheet
,
getStyleSheet
from
...common.icon
import
FluentIcon
class
NavigationDisplayMode
(
Enum
):
...
...
@@ -95,7 +96,7 @@ class NavigationPanel(QFrame):
self
.
topLayout
.
addWidget
(
self
.
menuButton
,
0
,
Qt
.
AlignTop
)
def
addItem
(
self
,
routeKey
:
str
,
icon
Path
:
str
,
text
:
str
,
onClick
,
selectable
=
True
,
position
=
NavigationItemPostion
.
TOP
):
def
addItem
(
self
,
routeKey
:
str
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
text
:
str
,
onClick
,
selectable
=
True
,
position
=
NavigationItemPostion
.
TOP
):
""" add navigation item
Parameters
...
...
@@ -103,8 +104,8 @@ class NavigationPanel(QFrame):
routeKey: str
the unique name of item
icon
Path: str
the
svg icon path
of navigation item
icon
: str | QIcon | FluentIcon
the
icon
of navigation item
text: str
the text of navigation item
...
...
@@ -121,7 +122,7 @@ class NavigationPanel(QFrame):
if
text
in
self
.
items
:
return
button
=
NavigationButton
(
icon
Path
,
text
,
selectable
,
self
)
button
=
NavigationButton
(
icon
,
text
,
selectable
,
self
)
self
.
addWidget
(
routeKey
,
button
,
onClick
,
position
)
def
addWidget
(
self
,
routeKey
:
str
,
widget
:
NavigationWidget
,
onClick
,
position
=
NavigationItemPostion
.
TOP
):
...
...
@@ -266,6 +267,9 @@ class NavigationPanel(QFrame):
w
=
QResizeEvent
(
e
).
size
().
width
()
if
w
<
1008
and
self
.
displayMode
==
NavigationDisplayMode
.
EXPAND
:
self
.
collapse
()
elif
w
>=
1008
and
self
.
displayMode
==
NavigationDisplayMode
.
COMPACT
and
\
not
self
.
menuButton
.
isVisible
():
self
.
expand
()
return
super
().
eventFilter
(
obj
,
e
)
...
...
qfluentwidgets/components/navigation/navigation_widget.py
浏览文件 @
d7df4155
# coding:utf-8
from
typing
import
Union
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QRect
,
QRectF
from
PyQt5.QtGui
import
QColor
,
QPainter
,
QPen
from
PyQt5.QtGui
import
QColor
,
QPainter
,
QPen
,
QIcon
from
PyQt5.QtWidgets
import
QWidget
from
...common.config
import
isDarkTheme
from
...common.icon
import
drawIcon
from
...common.icon
import
FluentIcon
Factory
as
FIF
from
...common.icon
import
FluentIcon
as
FIF
class
NavigationWidget
(
QWidget
):
...
...
@@ -71,19 +73,19 @@ class NavigationWidget(QWidget):
class
NavigationButton
(
NavigationWidget
):
""" Navigation button """
def
__init__
(
self
,
icon
Path
:
str
,
text
:
str
,
isSelectable
:
bool
,
parent
=
None
):
def
__init__
(
self
,
icon
:
Union
[
str
,
QIcon
,
FIF
]
,
text
:
str
,
isSelectable
:
bool
,
parent
=
None
):
"""
Parameters
----------
icon
Path: str
the
path of button ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
text: str
the text of button
"""
super
().
__init__
(
isSelectable
=
isSelectable
,
parent
=
parent
)
self
.
icon
Path
=
iconPath
self
.
icon
=
icon
self
.
_text
=
text
self
.
setStyleSheet
(
...
...
@@ -108,13 +110,14 @@ class NavigationButton(NavigationWidget):
painter
.
drawRoundedRect
(
self
.
rect
(),
5
,
5
)
# draw indicator
painter
.
setBrush
(
QColor
(
0
,
153
,
188
))
color
=
QColor
(
41
,
247
,
255
)
if
isDarkTheme
()
else
QColor
(
0
,
153
,
188
)
painter
.
setBrush
(
color
)
painter
.
drawRoundedRect
(
0
,
10
,
3
,
16
,
1.5
,
1.5
)
elif
self
.
isEnter
:
painter
.
setBrush
(
QColor
(
c
,
c
,
c
,
10
))
painter
.
drawRoundedRect
(
self
.
rect
(),
5
,
5
)
drawIcon
(
self
.
icon
Path
,
painter
,
QRectF
(
11.5
,
10
,
16
,
16
))
drawIcon
(
self
.
icon
,
painter
,
QRectF
(
11.5
,
10
,
16
,
16
))
# draw text
if
not
self
.
isCompacted
:
...
...
@@ -128,7 +131,7 @@ class MenuButton(NavigationButton):
""" Menu button """
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
FIF
.
path
(
FIF
.
MENU
)
,
''
,
parent
)
super
().
__init__
(
FIF
.
MENU
,
''
,
parent
)
def
setCompacted
(
self
,
isCompacted
:
bool
):
self
.
setFixedSize
(
40
,
36
)
...
...
qfluentwidgets/components/settings/expand_setting_card.py
浏览文件 @
d7df4155
# coding:utf-8
from
typing
import
Union
from
PyQt5.QtGui
import
QIcon
from
PyQt5.QtCore
import
(
QEvent
,
Qt
,
QPropertyAnimation
,
pyqtProperty
,
QEasingCurve
,
QParallelAnimationGroup
,
QRect
,
QSize
,
QPoint
,
QRectF
)
from
PyQt5.QtGui
import
QColor
,
QPainter
from
PyQt5.QtWidgets
import
QFrame
,
QWidget
,
QAbstractButton
,
QApplication
from
...common.config
import
isDarkTheme
from
...common.icon
import
FluentIcon
Factory
as
FIF
from
...common.icon
import
FluentIcon
as
FIF
from
...common.style_sheet
import
setStyleSheet
from
.setting_card
import
SettingCard
from
..layout.v_box_layout
import
VBoxLayout
...
...
@@ -44,7 +46,7 @@ class ExpandButton(QAbstractButton):
# draw icon
painter
.
translate
(
self
.
width
()
//
2
,
self
.
height
()
//
2
)
painter
.
rotate
(
self
.
__angle
)
FIF
.
render
(
FIF
.
ARROW_DOWN
,
painter
,
QRectF
(
-
6
,
-
6
,
9.6
,
9.6
))
FIF
.
ARROW_DOWN
.
render
(
painter
,
QRectF
(
-
6
,
-
6
,
9.6
,
9.6
))
def
enterEvent
(
self
,
e
):
self
.
setHover
(
True
)
...
...
@@ -86,12 +88,12 @@ class ExpandButton(QAbstractButton):
class
ExpandSettingCard
(
QFrame
):
""" Expandable setting card """
def
__init__
(
self
,
icon
Path
:
str
,
title
:
str
,
content
:
str
=
None
,
parent
=
None
):
def
__init__
(
self
,
icon
:
Union
[
str
,
QIcon
,
FIF
]
,
title
:
str
,
content
:
str
=
None
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
isExpand
=
False
self
.
expandButton
=
ExpandButton
(
self
)
self
.
view
=
QFrame
(
self
)
self
.
card
=
SettingCard
(
icon
Path
,
title
,
content
,
self
)
self
.
card
=
SettingCard
(
icon
,
title
,
content
,
self
)
self
.
viewLayout
=
VBoxLayout
(
self
.
view
)
# expand animation
...
...
qfluentwidgets/components/settings/folder_list_setting_card.py
浏览文件 @
d7df4155
...
...
@@ -3,13 +3,13 @@ from typing import List
from
pathlib
import
Path
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QRectF
from
PyQt5.QtGui
import
QPainter
from
PyQt5.QtGui
import
QPainter
,
QIcon
from
PyQt5.QtWidgets
import
(
QPushButton
,
QFileDialog
,
QWidget
,
QLabel
,
QHBoxLayout
,
QToolButton
)
from
...common.config
import
ConfigItem
,
qconfig
from
...common.icon
import
draw
Svg
Icon
from
...common.icon
import
FluentIcon
Factory
as
FIF
from
...common.icon
import
drawIcon
from
...common.icon
import
FluentIcon
as
FIF
from
..dialog_box.dialog
import
Dialog
from
.expand_setting_card
import
ExpandSettingCard
...
...
@@ -17,10 +17,10 @@ from .expand_setting_card import ExpandSettingCard
class
ToolButton
(
QToolButton
):
""" Tool button """
def
__init__
(
self
,
icon
Path
:
str
,
size
:
tuple
,
iconSize
:
tuple
,
parent
=
None
):
def
__init__
(
self
,
icon
,
size
:
tuple
,
iconSize
:
tuple
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
isPressed
=
False
self
.
iconPath
=
iconPath
self
.
_icon
=
icon
self
.
_iconSize
=
iconSize
self
.
setFixedSize
(
*
size
)
...
...
@@ -39,17 +39,17 @@ class ToolButton(QToolButton):
QPainter
.
SmoothPixmapTransform
)
painter
.
setOpacity
(
0.63
if
self
.
isPressed
else
1
)
w
,
h
=
self
.
_iconSize
draw
SvgIcon
(
self
.
iconPath
,
painter
,
QRectF
(
draw
Icon
(
self
.
_icon
,
painter
,
QRectF
(
(
self
.
width
()
-
w
)
//
2
,
(
self
.
height
()
-
h
)
//
2
,
w
,
h
))
class
PushButton
(
QPushButton
):
""" Push button """
def
__init__
(
self
,
icon
Path
:
str
,
text
:
str
,
parent
=
None
):
def
__init__
(
self
,
icon
,
text
:
str
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
isPressed
=
False
self
.
iconPath
=
iconPath
self
.
_icon
=
icon
self
.
setText
(
text
)
def
mousePressEvent
(
self
,
e
):
...
...
@@ -65,7 +65,7 @@ class PushButton(QPushButton):
painter
=
QPainter
(
self
)
painter
.
setRenderHints
(
QPainter
.
Antialiasing
)
painter
.
setOpacity
(
0.63
if
self
.
isPressed
else
1
)
draw
SvgIcon
(
self
.
iconPath
,
painter
,
QRectF
(
12
,
8
,
16
,
16
))
draw
Icon
(
self
.
_icon
,
painter
,
QRectF
(
12
,
8
,
16
,
16
))
class
FolderItem
(
QWidget
):
...
...
@@ -78,7 +78,7 @@ class FolderItem(QWidget):
self
.
folder
=
folder
self
.
hBoxLayout
=
QHBoxLayout
(
self
)
self
.
folderLabel
=
QLabel
(
folder
,
self
)
self
.
removeButton
=
ToolButton
(
FIF
.
path
(
FIF
.
CLOSE
)
,
(
39
,
29
),
(
12
,
12
),
self
)
self
.
removeButton
=
ToolButton
(
FIF
.
CLOSE
,
(
39
,
29
),
(
12
,
12
),
self
)
self
.
setFixedHeight
(
53
)
self
.
hBoxLayout
.
setContentsMargins
(
48
,
0
,
60
,
0
)
...
...
@@ -116,11 +116,10 @@ class FolderListSettingCard(ExpandSettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
FIF
.
path
(
FIF
.
FOLDER
)
,
title
,
content
,
parent
)
super
().
__init__
(
FIF
.
FOLDER
,
title
,
content
,
parent
)
self
.
configItem
=
configItem
self
.
_dialogDirectory
=
directory
self
.
addFolderButton
=
PushButton
(
FIF
.
path
(
FIF
.
FOLDER_ADD
),
self
.
tr
(
'Add folder'
),
self
)
self
.
addFolderButton
=
PushButton
(
FIF
.
FOLDER_ADD
,
self
.
tr
(
'Add folder'
),
self
)
self
.
folders
=
qconfig
.
get
(
configItem
).
copy
()
# type:List[str]
self
.
__initWidget
()
...
...
qfluentwidgets/components/settings/options_setting_card.py
浏览文件 @
d7df4155
# coding:utf-8
from
typing
import
List
from
typing
import
Union
from
PyQt5.QtCore
import
pyqtSignal
from
PyQt5.QtGui
import
QIcon
from
PyQt5.QtWidgets
import
QButtonGroup
,
QLabel
,
QRadioButton
from
...common.config
import
OptionsConfigItem
,
qconfig
from
...common.icon
import
FluentIcon
from
.expand_setting_card
import
ExpandSettingCard
...
...
@@ -12,15 +14,15 @@ class OptionsSettingCard(ExpandSettingCard):
optionChanged
=
pyqtSignal
(
OptionsConfigItem
)
def
__init__
(
self
,
configItem
,
icon
Path
,
title
,
content
=
None
,
texts
=
None
,
parent
=
None
):
def
__init__
(
self
,
configItem
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
texts
=
None
,
parent
=
None
):
"""
Parameters
----------
configItem: OptionsConfigItem
options config item
icon
Path: str
icon path
icon
: str | QIcon | FluentIcon
the icon to be drawn
title: str
the title of setting card
...
...
@@ -34,7 +36,7 @@ class OptionsSettingCard(ExpandSettingCard):
parent: QWidget
parent window
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
texts
=
texts
or
[]
self
.
configItem
=
configItem
self
.
configName
=
configItem
.
name
...
...
qfluentwidgets/components/settings/setting_card.py
浏览文件 @
d7df4155
# coding:utf-8
from
typing
import
Union
from
PyQt5.QtCore
import
QUrl
,
Qt
,
pyqtSignal
from
PyQt5.QtGui
import
QColor
,
QDesktopServices
from
PyQt5.QtGui
import
QColor
,
QDesktopServices
,
QIcon
from
PyQt5.QtWidgets
import
(
QFrame
,
QHBoxLayout
,
QLabel
,
QToolButton
,
QVBoxLayout
,
QPushButton
)
from
PyQt5.QtSvg
import
QSvgWidget
from
..dialog_box.color_dialog
import
ColorDialog
from
..widgets.combo_box
import
ComboBox
from
..widgets.switch_button
import
SwitchButton
,
IndicatorPosition
from
..widgets.slider
import
Slider
from
..widgets.icon_widget
import
IconWidget
from
...common.style_sheet
import
setStyleSheet
,
getStyleSheet
from
...common.config
import
qconfig
,
OptionsConfigItem
from
...common.config
import
qconfig
from
...common.icon
import
FluentIcon
class
SettingCard
(
QFrame
):
""" Setting card """
def
__init__
(
self
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
def
__init__
(
self
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
parent
=
None
):
"""
Parameters
----------
icon
Path: str
the
path of svg ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -33,7 +36,7 @@ class SettingCard(QFrame):
parent widget
"""
super
().
__init__
(
parent
=
parent
)
self
.
iconLabel
=
QSvgWidget
(
iconPath
,
self
)
self
.
iconLabel
=
IconWidget
(
icon
,
self
)
self
.
titleLabel
=
QLabel
(
title
,
self
)
self
.
contentLabel
=
QLabel
(
content
or
''
,
self
)
self
.
hBoxLayout
=
QHBoxLayout
(
self
)
...
...
@@ -81,12 +84,12 @@ class SwitchSettingCard(SettingCard):
checkedChanged
=
pyqtSignal
(
bool
)
def
__init__
(
self
,
icon
Path
,
title
,
content
=
None
,
configItem
=
None
,
parent
=
None
):
def
__init__
(
self
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
configItem
=
None
,
parent
=
None
):
"""
Parameters
----------
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -100,7 +103,7 @@ class SwitchSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
configItem
=
configItem
self
.
switchButton
=
SwitchButton
(
self
.
tr
(
'Off'
),
self
,
IndicatorPosition
.
RIGHT
)
...
...
@@ -139,15 +142,15 @@ class RangeSettingCard(SettingCard):
valueChanged
=
pyqtSignal
(
int
)
def
__init__
(
self
,
configItem
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
def
__init__
(
self
,
configItem
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
parent
=
None
):
"""
Parameters
----------
configItem: RangeConfigItem
configuration item operated by the card
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -158,7 +161,7 @@ class RangeSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
configItem
=
configItem
self
.
slider
=
Slider
(
Qt
.
Horizontal
,
self
)
self
.
valueLabel
=
QLabel
(
self
)
...
...
@@ -190,15 +193,15 @@ class PushSettingCard(SettingCard):
clicked
=
pyqtSignal
()
def
__init__
(
self
,
text
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
def
__init__
(
self
,
text
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
parent
=
None
):
"""
Parameters
----------
text: str
the text of push button
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -209,7 +212,7 @@ class PushSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
button
=
QPushButton
(
text
,
self
)
self
.
hBoxLayout
.
addWidget
(
self
.
button
,
0
,
Qt
.
AlignRight
)
self
.
hBoxLayout
.
addSpacing
(
16
)
...
...
@@ -219,15 +222,15 @@ class PushSettingCard(SettingCard):
class
PrimaryPushSettingCard
(
PushSettingCard
):
""" Push setting card with primary color """
def
__init__
(
self
,
text
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
super
().
__init__
(
text
,
icon
Path
,
title
,
content
,
parent
)
def
__init__
(
self
,
text
,
icon
,
title
,
content
=
None
,
parent
=
None
):
super
().
__init__
(
text
,
icon
,
title
,
content
,
parent
)
self
.
button
.
setObjectName
(
'primaryButton'
)
class
HyperlinkCard
(
SettingCard
):
""" Hyperlink card """
def
__init__
(
self
,
url
,
text
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
def
__init__
(
self
,
url
,
text
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
parent
=
None
):
"""
Parameters
----------
...
...
@@ -237,8 +240,8 @@ class HyperlinkCard(SettingCard):
text: str
text of url
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -252,7 +255,7 @@ class HyperlinkCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
url
=
QUrl
(
url
)
self
.
linkButton
=
QPushButton
(
text
,
self
)
...
...
@@ -307,15 +310,15 @@ class ColorSettingCard(SettingCard):
colorChanged
=
pyqtSignal
(
QColor
)
def
__init__
(
self
,
configItem
,
icon
Path
,
title
,
content
=
None
,
parent
=
None
):
def
__init__
(
self
,
configItem
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
parent
=
None
):
"""
Parameters
----------
configItem: RangeConfigItem
configuration item operated by the card
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -326,7 +329,7 @@ class ColorSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
configItem
=
configItem
self
.
colorPicker
=
ColorPickerButton
(
qconfig
.
get
(
configItem
),
title
,
self
)
...
...
@@ -342,15 +345,15 @@ class ColorSettingCard(SettingCard):
class
ComboBoxSettingCard
(
SettingCard
):
""" Setting card with a combo box """
def
__init__
(
self
,
configItem
,
icon
Path
,
title
,
content
=
None
,
texts
=
None
,
parent
=
None
):
def
__init__
(
self
,
configItem
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
]
,
title
,
content
=
None
,
texts
=
None
,
parent
=
None
):
"""
Parameters
----------
configItem: OptionsConfigItem
configuration item operated by the card
icon
Path: str
the
path of ico
n
icon
: str | QIcon | FluentIcon
the
icon to be draw
n
title: str
the title of card
...
...
@@ -364,7 +367,7 @@ class ComboBoxSettingCard(SettingCard):
parent: QWidget
parent widget
"""
super
().
__init__
(
icon
Path
,
title
,
content
,
parent
)
super
().
__init__
(
icon
,
title
,
content
,
parent
)
self
.
configItem
=
configItem
self
.
comboBox
=
ComboBox
(
self
)
self
.
hBoxLayout
.
addWidget
(
self
.
comboBox
,
0
,
Qt
.
AlignRight
)
...
...
qfluentwidgets/components/widgets/combo_box.py
浏览文件 @
d7df4155
...
...
@@ -4,8 +4,8 @@ from PyQt5.QtGui import QColor, QPainter
from
PyQt5.QtWidgets
import
QAction
,
QPushButton
,
QWidget
from
.menu
import
RoundMenu
from
...common.config
import
qconfig
,
isDarkTheme
from
...common.icon
import
FluentIcon
Factory
as
FIF
from
...common.config
import
isDarkTheme
from
...common.icon
import
FluentIcon
as
FIF
from
...common.style_sheet
import
setStyleSheet
...
...
@@ -155,7 +155,7 @@ class ComboBox(QPushButton):
elif
self
.
isPressed
:
painter
.
setOpacity
(
0.7
)
FIF
.
render
(
FIF
.
ARROW_DOWN
,
painter
,
QRectF
(
FIF
.
ARROW_DOWN
.
render
(
painter
,
QRectF
(
self
.
width
()
-
22
,
self
.
height
()
/
2
-
6
,
10
,
10
))
...
...
qfluentwidgets/components/widgets/icon_widget.py
0 → 100644
浏览文件 @
d7df4155
# coding:utf-8
from
typing
import
Union
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
from
PyQt5.QtGui
import
QIcon
,
QPainter
from
PyQt5.QtWidgets
import
QWidget
from
...common.icon
import
FluentIcon
,
drawIcon
class
IconWidget
(
QWidget
):
""" Icon widget """
def
__init__
(
self
,
icon
:
Union
[
str
,
QIcon
,
FluentIcon
],
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
icon
=
icon
def
paintEvent
(
self
,
e
):
painter
=
QPainter
(
self
)
painter
.
setRenderHints
(
QPainter
.
Antialiasing
|
QPainter
.
SmoothPixmapTransform
)
drawIcon
(
self
.
icon
,
painter
,
self
.
rect
())
qfluentwidgets/components/widgets/menu.py
浏览文件 @
d7df4155
...
...
@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QMenu, QProxyStyle, QStyle,
QListWidgetItem
)
from
...common.smooth_scroll
import
SmoothScroll
from
...common.icon
import
FluentIcon
Factory
as
FIF
from
...common.icon
import
FluentIcon
as
FIF
from
...common.icon
import
MenuIconEngine
from
...common.style_sheet
import
setStyleSheet
from
...common.config
import
isDarkTheme
...
...
@@ -100,7 +100,7 @@ class SubMenuItemWidget(QWidget):
painter
.
setRenderHints
(
QPainter
.
Antialiasing
)
# draw right arrow
FIF
.
render
(
FIF
.
CHEVRON_RIGHT
,
painter
,
QRectF
(
FIF
.
CHEVRON_RIGHT
.
render
(
painter
,
QRectF
(
self
.
width
()
-
10
,
self
.
height
()
/
2
-
9
/
2
,
9
,
9
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录