Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
9a08174e
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看板
提交
9a08174e
编写于
5月 24, 2022
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加动画层叠部件
上级
c00d5d50
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
256 addition
and
1 deletion
+256
-1
README.md
README.md
+16
-0
widgets/scroll_area/scroll_area.py
widgets/scroll_area/scroll_area.py
+1
-1
widgets/stacked_widget/stacked_widget.py
widgets/stacked_widget/stacked_widget.py
+239
-0
未找到文件。
README.md
浏览文件 @
9a08174e
...
...
@@ -171,6 +171,22 @@ A collection of commonly used widgets.
<code>
ScrollArea
</code>
</td>
</tr>
<tr>
<td>
Opacity Animation Stacked Widget
</td>
<td>
<code>
OpacityAniStackedWidget
</code>
</td>
</tr>
<tr>
<td>
Pop Up Animation Stacked Widget
</td>
<td>
<code>
PopUpAniStackedWidget
</code>
</td>
</tr>
</tbody>
</table>
...
...
widgets/scroll_area/scroll_area.py
浏览文件 @
9a08174e
...
...
@@ -4,7 +4,7 @@ from enum import Enum
from
math
import
cos
,
pi
from
PyQt5.QtCore
import
QDateTime
,
Qt
,
QTimer
,
QPoint
from
PyQt5.QtGui
import
QWheelEvent
,
QCursor
from
PyQt5.QtGui
import
QWheelEvent
from
PyQt5.QtWidgets
import
QApplication
,
QScrollArea
...
...
widgets/stacked_widget/stacked_widget.py
0 → 100644
浏览文件 @
9a08174e
# coding:utf-8
from
typing
import
List
from
PyQt5.QtCore
import
(
QAbstractAnimation
,
QEasingCurve
,
QParallelAnimationGroup
,
QPoint
,
QPropertyAnimation
,
pyqtSignal
)
from
PyQt5.QtWidgets
import
QGraphicsOpacityEffect
,
QStackedWidget
,
QWidget
class
OpacityAniStackedWidget
(
QStackedWidget
):
""" Stacked widget with fade in and fade out animation """
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
__nextIndex
=
0
self
.
__effects
=
[]
# type:List[QPropertyAnimation]
self
.
__anis
=
[]
# type:List[QPropertyAnimation]
def
addWidget
(
self
,
w
:
QWidget
):
super
().
addWidget
(
w
)
effect
=
QGraphicsOpacityEffect
(
self
)
effect
.
setOpacity
(
1
)
ani
=
QPropertyAnimation
(
effect
,
b
'opacity'
,
self
)
ani
.
setDuration
(
220
)
ani
.
finished
.
connect
(
self
.
__onAniFinished
)
self
.
__anis
.
append
(
ani
)
self
.
__effects
.
append
(
effect
)
w
.
setGraphicsEffect
(
effect
)
def
setCurrentIndex
(
self
,
index
:
int
):
index_
=
self
.
currentIndex
()
if
index
==
index_
:
return
if
index
>
index_
:
ani
=
self
.
__anis
[
index
]
ani
.
setStartValue
(
0
)
ani
.
setEndValue
(
1
)
super
().
setCurrentIndex
(
index
)
else
:
ani
=
self
.
__anis
[
index_
]
ani
.
setStartValue
(
1
)
ani
.
setEndValue
(
0
)
self
.
widget
(
index_
).
show
()
self
.
__nextIndex
=
index
ani
.
start
()
def
setCurrentWidget
(
self
,
w
:
QWidget
):
self
.
setCurrentIndex
(
self
.
indexOf
(
w
))
def
__onAniFinished
(
self
):
super
().
setCurrentIndex
(
self
.
__nextIndex
)
class
PopUpAniStackedWidget
(
QStackedWidget
):
""" Stacked widget with pop up animation """
aniFinished
=
pyqtSignal
()
aniStart
=
pyqtSignal
()
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
self
.
__widgetAni_list
=
[]
self
.
__nextIndex
=
None
self
.
__currentAniGroup
=
None
self
.
__previousWidget
=
None
self
.
__previousIndex
=
0
def
addWidget
(
self
,
widget
,
deltaX
:
int
=
0
,
deltaY
:
int
=
22
,
isNeedOpacityAni
=
False
):
""" add widget to window
Parameters
-----------
widget:
widget to be added
deltaX: int
the x-axis offset from the beginning to the end of animation
deltaY: int
the y-axis offset from the beginning to the end of animation
isNeedOpacityAni: bool
need fade in and fade out animation or not
"""
super
().
addWidget
(
widget
)
popUpAni
=
QPropertyAnimation
(
widget
,
b
'pos'
)
aniGroup
=
QParallelAnimationGroup
(
self
)
aniGroup
.
addAnimation
(
popUpAni
)
self
.
__widgetAni_list
.
append
({
'widget'
:
widget
,
'deltaX'
:
deltaX
,
'deltaY'
:
deltaY
,
'aniGroup'
:
aniGroup
,
'popUpAni'
:
popUpAni
,
'isNeedOpacityAni'
:
isNeedOpacityAni
})
def
setCurrentIndex
(
self
,
index
:
int
,
isNeedPopOut
:
bool
=
False
,
isShowNextWidgetDirectly
:
bool
=
True
,
duration
:
int
=
250
,
easingCurve
=
QEasingCurve
.
OutQuad
):
""" set current window to display
Parameters
----------
index: int
the index of widget to display
isNeedPopOut: bool
need pop up animation or not
isShowNextWidgetDirectly: bool
whether to show next widget directly when animation started
duration: int
animation duration
easingCurve: QEasingCurve
the interpolation mode of animation
"""
if
index
<
0
or
index
>=
self
.
count
():
raise
Exception
(
f
'The index `
{
index
}
` is illegal'
)
if
index
==
self
.
currentIndex
():
return
if
self
.
__currentAniGroup
and
self
.
__currentAniGroup
.
state
()
==
QAbstractAnimation
.
Running
:
return
# get the index of widget to be displayed
self
.
__nextIndex
=
index
self
.
__previousIndex
=
self
.
currentIndex
()
self
.
__previousWidget
=
self
.
currentWidget
()
self
.
__isNeedPopOut
=
isNeedPopOut
# get animation
nextWidgetAni_dict
=
self
.
__widgetAni_list
[
index
]
currentWidgetAni_dict
=
self
.
__widgetAni_list
[
self
.
currentIndex
()]
self
.
__currentWidget
=
self
.
currentWidget
()
# type:QWidget
self
.
__nextWidget
=
nextWidgetAni_dict
[
'widget'
]
# type:QWidget
currentPopUpAni
=
currentWidgetAni_dict
[
'popUpAni'
]
nextPopUpAni
=
nextWidgetAni_dict
[
'popUpAni'
]
self
.
__isNextWidgetNeedOpAni
=
nextWidgetAni_dict
[
'isNeedOpacityAni'
]
self
.
__isCurrentWidgetNeedOpAni
=
currentWidgetAni_dict
[
'isNeedOpacityAni'
]
self
.
__currentAniGroup
=
currentWidgetAni_dict
[
'aniGroup'
]
if
isNeedPopOut
else
nextWidgetAni_dict
[
'aniGroup'
]
# type:QParallelAnimationGroup
# set opacity animation
if
self
.
__isNextWidgetNeedOpAni
:
nextOpacityEffect
=
QGraphicsOpacityEffect
(
self
)
self
.
__nextOpacityAni
=
QPropertyAnimation
(
nextOpacityEffect
,
b
'opacity'
)
self
.
__nextWidget
.
setGraphicsEffect
(
nextOpacityEffect
)
self
.
__currentAniGroup
.
addAnimation
(
self
.
__nextOpacityAni
)
self
.
__setAnimation
(
self
.
__nextOpacityAni
,
0
,
1
,
duration
)
if
self
.
__isCurrentWidgetNeedOpAni
:
currentOpacityEffect
=
QGraphicsOpacityEffect
(
self
)
self
.
__currentOpacityAni
=
QPropertyAnimation
(
currentOpacityEffect
,
b
'opacity'
)
self
.
__currentWidget
.
setGraphicsEffect
(
currentOpacityEffect
)
self
.
__currentAniGroup
.
addAnimation
(
self
.
__currentOpacityAni
)
self
.
__setAnimation
(
self
.
__currentOpacityAni
,
1
,
0
,
duration
)
if
isNeedPopOut
:
deltaX
=
currentWidgetAni_dict
[
'deltaX'
]
deltaY
=
currentWidgetAni_dict
[
'deltaY'
]
pos
=
self
.
__currentWidget
.
pos
()
+
QPoint
(
deltaX
,
deltaY
)
self
.
__setAnimation
(
currentPopUpAni
,
self
.
__currentWidget
.
pos
(),
pos
,
duration
,
easingCurve
)
self
.
__nextWidget
.
setVisible
(
isShowNextWidgetDirectly
)
else
:
deltaX
=
nextWidgetAni_dict
[
'deltaX'
]
deltaY
=
nextWidgetAni_dict
[
'deltaY'
]
pos
=
self
.
__nextWidget
.
pos
()
+
QPoint
(
deltaX
,
deltaY
)
self
.
__setAnimation
(
nextPopUpAni
,
pos
,
QPoint
(
self
.
__nextWidget
.
x
(),
self
.
y
()),
duration
,
easingCurve
)
super
().
setCurrentIndex
(
index
)
# start animation
self
.
__currentAniGroup
.
finished
.
connect
(
self
.
__aniFinishedSlot
)
self
.
__currentAniGroup
.
start
()
self
.
aniStart
.
emit
()
def
setCurrentWidget
(
self
,
widget
,
isNeedPopOut
:
bool
=
False
,
isShowNextWidgetDirectly
:
bool
=
True
,
duration
:
int
=
250
,
easingCurve
=
QEasingCurve
.
OutQuad
):
""" set currect widget
Parameters
----------
widget:
the widget to be displayed
isNeedPopOut: bool
need pop up animation or not
isShowNextWidgetDirectly: bool
whether to show next widget directly when animation started
duration: int
animation duration
easingCurve: QEasingCurve
the interpolation mode of animation
"""
self
.
setCurrentIndex
(
self
.
indexOf
(
widget
),
isNeedPopOut
,
isShowNextWidgetDirectly
,
duration
,
easingCurve
)
def
__setAnimation
(
self
,
ani
:
QPropertyAnimation
,
startValue
,
endValue
,
duration
,
easingCurve
=
QEasingCurve
.
Linear
):
""" set the config of animation """
ani
.
setEasingCurve
(
easingCurve
)
ani
.
setStartValue
(
startValue
)
ani
.
setEndValue
(
endValue
)
ani
.
setDuration
(
duration
)
def
__aniFinishedSlot
(
self
):
""" animation finished slot """
# cancel previously opacity effects to prevent conflicts with the opacity effects of widgets
if
self
.
__isCurrentWidgetNeedOpAni
:
self
.
__currentWidget
.
setGraphicsEffect
(
None
)
self
.
__currentAniGroup
.
removeAnimation
(
self
.
__currentOpacityAni
)
if
self
.
__isNextWidgetNeedOpAni
:
self
.
__nextWidget
.
setGraphicsEffect
(
None
)
self
.
__currentAniGroup
.
removeAnimation
(
self
.
__nextOpacityAni
)
self
.
__currentAniGroup
.
disconnect
()
super
().
setCurrentIndex
(
self
.
__nextIndex
)
self
.
aniFinished
.
emit
()
@
property
def
previousWidget
(
self
):
return
self
.
__previousWidget
@
property
def
previousIndex
(
self
):
return
self
.
__previousIndex
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录