Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
6e522732
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看板
提交
6e522732
编写于
8月 08, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加背景过渡效果
上级
430e29c2
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
77632 addition
and
77541 deletion
+77632
-77541
examples/window/demo.py
examples/window/demo.py
+1
-1
qfluentwidgets/_rc/qss/dark/fluent_window.qss
qfluentwidgets/_rc/qss/dark/fluent_window.qss
+2
-10
qfluentwidgets/_rc/qss/light/fluent_window.qss
qfluentwidgets/_rc/qss/light/fluent_window.qss
+2
-2
qfluentwidgets/_rc/resource.py
qfluentwidgets/_rc/resource.py
+77486
-77487
qfluentwidgets/common/animation.py
qfluentwidgets/common/animation.py
+108
-2
qfluentwidgets/common/style_sheet.py
qfluentwidgets/common/style_sheet.py
+1
-1
qfluentwidgets/components/widgets/card_widget.py
qfluentwidgets/components/widgets/card_widget.py
+25
-31
qfluentwidgets/components/widgets/tab_view.py
qfluentwidgets/components/widgets/tab_view.py
+1
-0
qfluentwidgets/window/fluent_window.py
qfluentwidgets/window/fluent_window.py
+6
-7
未找到文件。
examples/window/demo.py
浏览文件 @
6e522732
...
...
@@ -101,7 +101,7 @@ if __name__ == '__main__':
QApplication
.
setAttribute
(
Qt
.
AA_EnableHighDpiScaling
)
QApplication
.
setAttribute
(
Qt
.
AA_UseHighDpiPixmaps
)
#
setTheme(Theme.DARK)
setTheme
(
Theme
.
DARK
)
app
=
QApplication
(
sys
.
argv
)
w
=
Window
()
...
...
qfluentwidgets/_rc/qss/dark/fluent_window.qss
浏览文件 @
6e522732
FluentWindowBase {
background-color: rgb(32, 32, 32);
}
FluentTitleBar, SplitTitleBar {
background-color: transparent;
}
...
...
@@ -48,17 +44,13 @@ CloseButton {
}
StackedWidget {
border: 1px solid rgb
(29, 29, 29
);
border: 1px solid rgb
a(0, 0, 0, 0.18
);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb
(39, 39, 39
);
background-color: rgb
a(255, 255, 255, 0.0314
);
}
/* StackedWidget QLabel {
color: white;
} */
SplitFluentWindow > StackedWidget {
border-top-left-radius: 0px;
border-top: none;
...
...
qfluentwidgets/_rc/qss/light/fluent_window.qss
浏览文件 @
6e522732
StackedWidget {
border: 1px solid rgb
(229, 229, 229
);
border: 1px solid rgb
a(0, 0, 0, 0.068
);
border-right: none;
border-bottom: none;
border-top-left-radius: 10px;
background-color: rgb
(249, 249, 249
);
background-color: rgb
a(255, 255, 255, 0.5
);
}
SplitFluentWindow>StackedWidget {
...
...
qfluentwidgets/_rc/resource.py
浏览文件 @
6e522732
此差异已折叠。
点击以展开。
qfluentwidgets/common/animation.py
浏览文件 @
6e522732
# coding: utf-8
from
PyQt5.QtCore
import
QEasingCurve
,
QEvent
,
QObject
,
QPropertyAnimation
,
pyqtProperty
,
pyqtSignal
from
PyQt5.QtGui
import
QMouseEvent
,
QEnterEvent
from
PyQt5.QtWidgets
import
QWidget
from
PyQt5.QtGui
import
QMouseEvent
,
QEnterEvent
,
QColor
from
PyQt5.QtWidgets
import
QWidget
,
QLineEdit
from
.config
import
qconfig
class
AnimationBase
(
QObject
):
...
...
@@ -72,3 +73,108 @@ class TranslateYAnimation(AnimationBase):
self
.
ani
.
setEasingCurve
(
QEasingCurve
.
OutElastic
)
self
.
ani
.
start
()
class
BackgroundAnimationWidget
:
""" Background animation widget """
def
__init__
(
self
,
*
args
,
**
kwargs
)
->
None
:
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
isHover
=
False
self
.
isPressed
=
False
self
.
bgColorObject
=
BackgroundColorObject
(
self
)
self
.
backgroundColorAni
=
QPropertyAnimation
(
self
.
bgColorObject
,
b
'backgroundColor'
,
self
)
self
.
backgroundColorAni
.
setDuration
(
120
)
self
.
installEventFilter
(
self
)
qconfig
.
themeChanged
.
connect
(
self
.
_updateBackgroundColor
)
def
eventFilter
(
self
,
obj
,
e
):
if
obj
is
self
:
if
e
.
type
()
==
QEvent
.
Type
.
EnabledChange
:
if
self
.
isEnabled
():
self
.
setBackgroundColor
(
self
.
_normalBackgroundColor
())
else
:
self
.
setBackgroundColor
(
self
.
_disabledBackgroundColor
())
return
super
().
eventFilter
(
obj
,
e
)
def
mousePressEvent
(
self
,
e
):
self
.
isPressed
=
True
self
.
_updateBackgroundColor
()
super
().
mousePressEvent
(
e
)
def
mouseReleaseEvent
(
self
,
e
):
self
.
isPressed
=
False
self
.
_updateBackgroundColor
()
super
().
mouseReleaseEvent
(
e
)
def
enterEvent
(
self
,
e
):
self
.
isHover
=
True
self
.
_updateBackgroundColor
()
def
leaveEvent
(
self
,
e
):
self
.
isHover
=
False
self
.
_updateBackgroundColor
()
def
focusInEvent
(
self
,
e
):
super
().
focusInEvent
(
e
)
self
.
_updateBackgroundColor
()
def
_normalBackgroundColor
(
self
):
return
QColor
(
0
,
0
,
0
,
0
)
def
_hoverBackgroundColor
(
self
):
return
self
.
_normalBackgroundColor
()
def
_pressedBackgroundColor
(
self
):
return
self
.
_normalBackgroundColor
()
def
_focusInBackgroundColor
(
self
):
return
self
.
_normalBackgroundColor
()
def
_disabledBackgroundColor
(
self
):
return
self
.
_normalBackgroundColor
()
def
_updateBackgroundColor
(
self
):
if
not
self
.
isEnabled
():
color
=
self
.
_disabledBackgroundColor
()
elif
isinstance
(
self
,
QLineEdit
)
and
self
.
hasFocus
():
color
=
self
.
_focusInBackgroundColor
()
elif
self
.
isPressed
:
color
=
self
.
_pressedBackgroundColor
()
elif
self
.
isHover
:
color
=
self
.
_hoverBackgroundColor
()
else
:
color
=
self
.
_normalBackgroundColor
()
self
.
backgroundColorAni
.
stop
()
self
.
backgroundColorAni
.
setEndValue
(
color
)
self
.
backgroundColorAni
.
start
()
def
getBackgroundColor
(
self
):
return
self
.
bgColorObject
.
backgroundColor
def
setBackgroundColor
(
self
,
color
:
QColor
):
self
.
bgColorObject
.
backgroundColor
=
color
@
property
def
backgroundColor
(
self
):
return
self
.
getBackgroundColor
()
class
BackgroundColorObject
(
QObject
):
""" Background color object """
def
__init__
(
self
,
parent
:
BackgroundAnimationWidget
):
super
().
__init__
(
parent
)
self
.
_backgroundColor
=
parent
.
_normalBackgroundColor
()
@
pyqtProperty
(
QColor
)
def
backgroundColor
(
self
):
return
self
.
_backgroundColor
@
backgroundColor
.
setter
def
backgroundColor
(
self
,
color
:
QColor
):
self
.
_backgroundColor
=
color
self
.
parent
().
update
()
qfluentwidgets/common/style_sheet.py
浏览文件 @
6e522732
...
...
@@ -118,7 +118,7 @@ class FluentStyleSheet(StyleSheetBase, Enum):
def
path
(
self
,
theme
=
Theme
.
AUTO
):
theme
=
qconfig
.
theme
if
theme
==
Theme
.
AUTO
else
theme
return
f
"
:/qfluentwidgets
/qss/
{
theme
.
value
.
lower
()
}
/
{
self
.
value
}
.qss"
return
f
"
qfluentwidgets/_rc
/qss/
{
theme
.
value
.
lower
()
}
/
{
self
.
value
}
.qss"
def
getStyleSheet
(
file
:
Union
[
str
,
StyleSheetBase
],
theme
=
Theme
.
AUTO
):
...
...
qfluentwidgets/components/widgets/card_widget.py
浏览文件 @
6e522732
# coding:utf-8
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QRectF
from
PyQt5.QtCore
import
Qt
,
pyqtSignal
,
QRectF
,
pyqtProperty
from
PyQt5.QtGui
import
QPixmap
,
QPainter
,
QColor
,
QPainterPath
from
PyQt5.QtWidgets
import
QWidget
,
QFrame
from
...common.style_sheet
import
isDarkTheme
from
...common.animation
import
BackgroundAnimationWidget
class
CardWidget
(
QFrame
):
class
CardWidget
(
BackgroundAnimationWidget
,
QFrame
):
""" Card widget """
clicked
=
pyqtSignal
()
...
...
@@ -14,26 +15,12 @@ class CardWidget(QFrame):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
_isClickEnabled
=
False
self
.
isPressed
=
False
self
.
isHover
=
False
def
mousePressEvent
(
self
,
e
):
self
.
isPressed
=
True
self
.
update
()
self
.
_borderRadius
=
5
def
mouseReleaseEvent
(
self
,
e
):
self
.
isPressed
=
False
self
.
update
()
super
().
mouseReleaseEvent
(
e
)
self
.
clicked
.
emit
()
def
enterEvent
(
self
,
e
):
self
.
isHover
=
True
self
.
update
()
def
leaveEvent
(
self
,
e
):
self
.
isHover
=
False
self
.
update
()
def
setClickEnabled
(
self
,
isEnabled
:
bool
):
self
.
_isClickEnabled
=
isEnabled
self
.
update
()
...
...
@@ -41,6 +28,22 @@ class CardWidget(QFrame):
def
isClickEnabled
(
self
):
return
self
.
_isClickEnabled
def
_normalBackgroundColor
(
self
):
return
QColor
(
255
,
255
,
255
,
13
if
isDarkTheme
()
else
170
)
def
_hoverBackgroundColor
(
self
):
return
QColor
(
255
,
255
,
255
,
21
if
isDarkTheme
()
else
64
)
def
_pressedBackgroundColor
(
self
):
return
QColor
(
255
,
255
,
255
,
8
if
isDarkTheme
()
else
64
)
def
getBorderRadius
(
self
):
return
self
.
_borderRadius
def
setBorderRadius
(
self
,
radius
:
int
):
self
.
_borderRadius
=
radius
self
.
update
()
def
paintEvent
(
self
,
e
):
painter
=
QPainter
(
self
)
painter
.
setRenderHints
(
QPainter
.
Antialiasing
)
...
...
@@ -89,17 +92,8 @@ class CardWidget(QFrame):
# draw background
painter
.
setPen
(
Qt
.
NoPen
)
alpha
=
170
if
isDark
:
if
self
.
isPressed
:
alpha
=
8
elif
self
.
isHover
:
alpha
=
21
else
:
alpha
=
13
elif
self
.
isPressed
or
self
.
isHover
:
alpha
=
64
rect
=
self
.
rect
().
adjusted
(
1
,
1
,
-
1
,
-
1
)
painter
.
setBrush
(
QColor
(
255
,
255
,
255
,
alpha
))
painter
.
drawRoundedRect
(
rect
,
r
,
r
)
\ No newline at end of file
painter
.
setBrush
(
self
.
backgroundColor
)
painter
.
drawRoundedRect
(
rect
,
r
,
r
)
borderRadius
=
pyqtProperty
(
int
,
getBorderRadius
,
setBorderRadius
)
qfluentwidgets/components/widgets/tab_view.py
浏览文件 @
6e522732
...
...
@@ -90,6 +90,7 @@ class TabItem(PushButton):
self
.
setMaximumWidth
(
240
)
self
.
setMinimumWidth
(
64
)
self
.
installEventFilter
(
ToolTipFilter
(
self
,
showDelay
=
1000
))
self
.
setAttribute
(
Qt
.
WA_LayoutUsesWidgetRect
)
self
.
closeButton
.
setIconSize
(
QSize
(
10
,
10
))
...
...
qfluentwidgets/window/fluent_window.py
浏览文件 @
6e522732
...
...
@@ -8,6 +8,7 @@ from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel
from
..common.icon
import
FluentIconBase
from
..common.router
import
qrouter
from
..common.style_sheet
import
FluentStyleSheet
,
isDarkTheme
from
..common.animation
import
BackgroundAnimationWidget
from
..components.widgets.frameless_window
import
FramelessWindow
from
..components.navigation
import
(
NavigationInterface
,
NavigationBar
,
NavigationItemPosition
,
NavigationBarPushButton
,
NavigationTreeWidget
)
...
...
@@ -16,7 +17,7 @@ from .stacked_widget import StackedWidget
from
qframelesswindow
import
TitleBar
class
FluentWindowBase
(
FramelessWindow
):
class
FluentWindowBase
(
BackgroundAnimationWidget
,
FramelessWindow
):
""" Fluent window base class """
def
__init__
(
self
,
parent
=
None
):
...
...
@@ -44,16 +45,14 @@ class FluentWindowBase(FramelessWindow):
self
.
navigationInterface
.
setCurrentItem
(
widget
.
objectName
())
qrouter
.
push
(
self
.
stackedWidget
,
widget
.
objectName
())
def
_normalBackgroundColor
(
self
):
return
QColor
(
32
,
32
,
32
)
if
isDarkTheme
()
else
QColor
(
243
,
243
,
243
)
def
paintEvent
(
self
,
e
):
super
().
paintEvent
(
e
)
painter
=
QPainter
(
self
)
painter
.
setPen
(
Qt
.
NoPen
)
if
isDarkTheme
():
painter
.
setBrush
(
QColor
(
32
,
32
,
32
))
else
:
painter
.
setBrush
(
QColor
(
243
,
243
,
243
))
painter
.
setBrush
(
self
.
backgroundColor
)
painter
.
drawRect
(
self
.
rect
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录