Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
c3d8f0c2
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看板
提交
c3d8f0c2
编写于
4月 26, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes #147
上级
0ee019b1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
63 deletion
+53
-63
.gitignore
.gitignore
+3
-0
qfluentwidgets/components/widgets/info_bar.py
qfluentwidgets/components/widgets/info_bar.py
+50
-63
未找到文件。
.gitignore
浏览文件 @
c3d8f0c2
...
...
@@ -5,6 +5,9 @@
# 忽略工作区文件
*.code-workspace
# 忽略 .idea
.idea/
# 忽略python缓存文件
*/__pycache__
*.py[cod]
...
...
qfluentwidgets/components/widgets/info_bar.py
浏览文件 @
c3d8f0c2
...
...
@@ -13,26 +13,9 @@ from ...common.auto_wrap import TextWrap
from
...common.style_sheet
import
FluentStyleSheet
,
themeColor
from
...common.icon
import
FluentIconBase
,
Theme
,
isDarkTheme
,
writeSvg
,
drawSvgIcon
,
drawIcon
from
...common.icon
import
FluentIcon
as
FIF
from
.button
import
TransparentToolButton
class
InfoBarCloseButton
(
QToolButton
):
""" Close button """
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
setFixedSize
(
36
,
36
)
self
.
setIconSize
(
QSize
(
12
,
12
))
self
.
setCursor
(
Qt
.
PointingHandCursor
)
self
.
setObjectName
(
'infoBarCloseButton'
)
FluentStyleSheet
.
INFO_BAR
.
apply
(
self
)
def
paintEvent
(
self
,
e
):
super
().
paintEvent
(
e
)
painter
=
QPainter
(
self
)
painter
.
setRenderHints
(
QPainter
.
Antialiasing
|
QPainter
.
SmoothPixmapTransform
)
FIF
.
CLOSE
.
render
(
painter
,
QRectF
(
12
,
12
,
12
,
12
))
class
InfoBarIcon
(
FluentIconBase
,
Enum
):
""" Info bar icon """
...
...
@@ -67,7 +50,7 @@ class InfoIconWidget(QWidget):
def
__init__
(
self
,
icon
:
InfoBarIcon
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
self
.
setFixedSize
(
15
,
15
)
self
.
setFixedSize
(
36
,
36
)
self
.
icon
=
icon
def
paintEvent
(
self
,
e
):
...
...
@@ -75,10 +58,11 @@ class InfoIconWidget(QWidget):
painter
.
setRenderHints
(
QPainter
.
Antialiasing
|
QPainter
.
SmoothPixmapTransform
)
rect
=
QRectF
(
10
,
10
,
15
,
15
)
if
self
.
icon
!=
InfoBarIcon
.
INFORMATION
:
drawIcon
(
self
.
icon
,
painter
,
self
.
rect
()
)
drawIcon
(
self
.
icon
,
painter
,
rect
)
else
:
drawIcon
(
self
.
icon
,
painter
,
self
.
rect
()
,
indexes
=
[
0
],
fill
=
themeColor
().
name
())
drawIcon
(
self
.
icon
,
painter
,
rect
,
indexes
=
[
0
],
fill
=
themeColor
().
name
())
class
InfoBar
(
QFrame
):
...
...
@@ -123,14 +107,14 @@ class InfoBar(QFrame):
self
.
isClosable
=
isClosable
self
.
position
=
position
self
.
titleLabel
=
QLabel
(
title
,
self
)
self
.
titleLabel
=
QLabel
(
self
)
self
.
contentLabel
=
QLabel
(
self
)
self
.
closeButton
=
InfoBarCloseButton
(
self
)
self
.
closeButton
=
TransparentToolButton
(
FIF
.
CLOSE
,
self
)
self
.
iconWidget
=
InfoIconWidget
(
icon
)
self
.
vBoxLayout
=
QV
BoxLayout
(
self
)
self
.
hBoxLayout
=
QH
BoxLayout
()
self
.
conten
tLayout
=
QHBoxLayout
()
if
self
.
orient
==
Qt
.
Horizontal
else
QVBoxLayout
()
self
.
hBoxLayout
=
QH
BoxLayout
(
self
)
self
.
textLayout
=
QHBoxLayout
()
if
self
.
orient
==
Qt
.
Horizontal
else
QV
BoxLayout
()
self
.
widge
tLayout
=
QHBoxLayout
()
if
self
.
orient
==
Qt
.
Horizontal
else
QVBoxLayout
()
self
.
opacityEffect
=
QGraphicsOpacityEffect
(
self
)
self
.
opacityAni
=
QPropertyAnimation
(
...
...
@@ -142,57 +126,56 @@ class InfoBar(QFrame):
self
.
__initWidget
()
def
__initWidget
(
self
):
self
.
titleLabel
.
setMinimumHeight
(
36
)
self
.
opacityEffect
.
setOpacity
(
1
)
self
.
setGraphicsEffect
(
self
.
opacityEffect
)
self
.
closeButton
.
setFixedSize
(
36
,
36
)
self
.
closeButton
.
setIconSize
(
QSize
(
12
,
12
))
self
.
closeButton
.
setCursor
(
Qt
.
PointingHandCursor
)
self
.
closeButton
.
setVisible
(
self
.
isClosable
)
self
.
__initLayout
()
self
.
__setQss
()
self
.
__initLayout
()
self
.
closeButton
.
clicked
.
connect
(
self
.
close
)
def
__initLayout
(
self
):
self
.
vBoxLayout
.
setContentsMargins
(
0
,
0
,
0
,
0
)
self
.
vBoxLayout
.
setSizeConstraint
(
QVBoxLayout
.
SetMinimumSize
)
self
.
contentLayout
.
setSizeConstraint
(
QHBoxLayout
.
SetMinimumSize
)
self
.
hBoxLayout
.
setContentsMargins
(
6
,
6
,
6
,
6
)
self
.
hBoxLayout
.
setSizeConstraint
(
QVBoxLayout
.
SetMinimumSize
)
self
.
textLayout
.
setSizeConstraint
(
QHBoxLayout
.
SetMinimumSize
)
self
.
textLayout
.
setAlignment
(
Qt
.
AlignTop
)
self
.
textLayout
.
setContentsMargins
(
1
,
8
,
0
,
8
)
self
.
vBoxLayout
.
setSpacing
(
0
)
self
.
hBoxLayout
.
setSpacing
(
0
)
self
.
textLayout
.
setSpacing
(
5
)
self
.
vBoxLayout
.
addLayout
(
self
.
hBoxLayout
)
self
.
hBoxLayout
.
addWidget
(
self
.
iconWidget
)
# add icon to layout
self
.
hBoxLayout
.
addWidget
(
self
.
iconWidget
,
0
,
Qt
.
AlignTop
|
Qt
.
AlignLeft
)
if
self
.
title
:
self
.
hBoxLayout
.
addSpacing
(
15
)
self
.
hBoxLayout
.
addWidget
(
self
.
titleLabel
)
else
:
self
.
titleLabel
.
hide
()
# add title to layout
self
.
textLayout
.
addWidget
(
self
.
titleLabel
,
1
,
Qt
.
AlignTop
)
self
.
titleLabel
.
setVisible
(
bool
(
self
.
title
))
# add content label to layout
if
self
.
orient
==
Qt
.
Horizontal
:
self
.
vBoxLayout
.
setAlignment
(
Qt
.
AlignVCenter
)
self
.
hBoxLayout
.
addSpacing
(
12
)
self
.
contentLayout
.
setContentsMargins
(
0
,
0
,
20
*
self
.
isClosable
,
0
)
self
.
contentLayout
.
setSpacing
(
12
)
self
.
hBoxLayout
.
addLayout
(
self
.
contentLayout
)
else
:
self
.
vBoxLayout
.
setAlignment
(
Qt
.
AlignTop
)
self
.
contentLayout
.
setContentsMargins
(
47
,
0
,
40
,
18
)
self
.
contentLayout
.
setSpacing
(
14
)
self
.
vBoxLayout
.
addLayout
(
self
.
contentLayout
)
self
.
contentLayout
.
setAlignment
(
Qt
.
AlignTop
)
self
.
textLayout
.
addSpacing
(
7
)
self
.
_adjustText
()
self
.
contentLayout
.
addWidget
(
self
.
contentLabel
)
self
.
textLayout
.
addWidget
(
self
.
contentLabel
,
1
,
Qt
.
AlignTop
)
self
.
contentLabel
.
setVisible
(
bool
(
self
.
content
))
self
.
hBoxLayout
.
addLayout
(
self
.
textLayout
)
# add close button to layout
if
self
.
isClosable
:
self
.
hBoxLayout
.
addWidget
(
self
.
closeButton
)
mb
=
6
if
self
.
orient
==
Qt
.
Horizontal
else
0
self
.
hBoxLayout
.
setContentsMargins
(
16
,
6
,
7
,
mb
)
# add widget layout
if
self
.
orient
==
Qt
.
Horizontal
:
self
.
hBoxLayout
.
addLayout
(
self
.
widgetLayout
)
self
.
widgetLayout
.
setSpacing
(
10
)
else
:
self
.
hBoxLayout
.
setContentsMargins
(
16
,
6
,
16
,
6
)
self
.
textLayout
.
addLayout
(
self
.
widgetLayout
)
# add close button to layout
self
.
hBoxLayout
.
addSpacing
(
12
)
self
.
hBoxLayout
.
addWidget
(
self
.
closeButton
,
0
,
Qt
.
AlignTop
|
Qt
.
AlignLeft
)
self
.
_adjustText
()
def
__setQss
(
self
):
self
.
titleLabel
.
setObjectName
(
'titleLabel'
)
...
...
@@ -212,17 +195,21 @@ class InfoBar(QFrame):
def
_adjustText
(
self
):
w
=
900
if
not
self
.
parent
()
else
(
self
.
parent
().
width
()
-
50
)
# adjust title
chars
=
max
(
min
(
w
/
10
,
120
),
30
)
self
.
titleLabel
.
setText
(
TextWrap
.
wrap
(
self
.
title
,
chars
,
False
)[
0
])
# adjust content
chars
=
max
(
min
(
w
/
9
,
120
),
30
)
self
.
contentLabel
.
setText
(
TextWrap
.
wrap
(
self
.
content
,
chars
,
False
)[
0
])
self
.
adjustSize
()
def
adjustSize
(
self
):
super
().
adjustSize
()
self
.
resize
(
self
.
width
(),
max
(
self
.
height
(),
50
))
def
addWidget
(
self
,
widget
:
QWidget
,
stretch
=
0
):
""" add widget to info bar """
self
.
contentLayout
.
addWidget
(
widget
,
stretch
,
Qt
.
AlignLeft
)
self
.
widgetLayout
.
addSpacing
(
6
)
align
=
Qt
.
AlignTop
if
self
.
orient
==
Qt
.
Vertical
else
Qt
.
AlignVCenter
self
.
widgetLayout
.
addWidget
(
widget
,
stretch
,
Qt
.
AlignLeft
|
align
)
def
setCustomBackgroundColor
(
self
,
light
,
dark
):
""" set the custom background color
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录