Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
904d3c0a
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看板
提交
904d3c0a
编写于
8月 12, 2022
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提升工具提示为顶层窗口
上级
8007717b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
24 deletion
+41
-24
widgets/tool_tip/demo.py
widgets/tool_tip/demo.py
+2
-11
widgets/tool_tip/resource/tooltip.qss
widgets/tool_tip/resource/tooltip.qss
+4
-4
widgets/tool_tip/tool_tip.py
widgets/tool_tip/tool_tip.py
+35
-9
未找到文件。
widgets/tool_tip/demo.py
浏览文件 @
904d3c0a
...
...
@@ -14,7 +14,7 @@ class Demo(QWidget):
self
.
button1
=
QPushButton
(
'キラキラ'
,
self
)
self
.
button2
=
QPushButton
(
'食べた愛'
,
self
)
self
.
_toolTip
=
ToolTip
(
parent
=
self
)
# self._tool
t
ip.setDarkTheme(True)
# self._tool
T
ip.setDarkTheme(True)
self
.
button1
.
setToolTip
(
'aiko - キラキラ ✨'
)
self
.
button2
.
setToolTip
(
'aiko - 食べた愛 🥰'
)
...
...
@@ -43,16 +43,7 @@ class Demo(QWidget):
if
e
.
type
()
==
QEvent
.
Enter
:
tip
.
setText
(
obj
.
toolTip
())
tip
.
setDuration
(
obj
.
toolTipDuration
())
pos
=
obj
.
mapTo
(
self
,
QPoint
(
0
,
0
))
x
=
pos
.
x
()
+
obj
.
width
()
//
2
-
tip
.
width
()
//
2
y
=
pos
.
y
()
-
5
-
tip
.
height
()
# adjust postion to prevent tooltips from appearing outside the window
x
=
min
(
max
(
5
,
x
),
self
.
width
()
-
tip
.
width
()
-
5
)
y
=
min
(
max
(
5
,
y
),
self
.
height
()
-
tip
.
height
()
-
5
)
tip
.
move
(
x
,
y
)
tip
.
adjustPos
(
obj
.
mapToGlobal
(
QPoint
()),
obj
.
size
())
tip
.
show
()
elif
e
.
type
()
==
QEvent
.
Leave
:
tip
.
hide
()
...
...
widgets/tool_tip/resource/tooltip.qss
浏览文件 @
904d3c0a
ToolTip[dark=
"false"]
{
ToolTip[dark=
false]>QFrame
{
border: 1px solid rgba(0, 0, 0, 0.06);
border-radius: 5px;
background-color: rgb(243, 243, 243);
}
ToolTip[dark=
"true"]
{
ToolTip[dark=
true]>QFrame
{
border: 1px solid rgb(28, 28, 28);
border-radius: 5px;
background-color: rgb(43, 43, 43);
...
...
@@ -15,10 +15,10 @@ QLabel {
font: 15px 'Segoe UI', 'Microsoft YaHei';
}
QLabel[dark=
"false"
] {
QLabel[dark=
false
] {
color: black;
}
QLabel[dark=
"true"
] {
QLabel[dark=
true
] {
color: white;
}
\ No newline at end of file
widgets/tool_tip/tool_tip.py
浏览文件 @
904d3c0a
# coding:utf-8
from
PyQt5.QtCore
import
QFile
,
QPropertyAnimation
,
QTimer
,
Qt
from
PyQt5.QtCore
import
QFile
,
QPropertyAnimation
,
QTimer
,
Qt
,
QPoint
,
QSize
from
PyQt5.QtGui
import
QColor
from
PyQt5.QtWidgets
import
(
QApplication
,
QFrame
,
QGraphicsDropShadowEffect
,
QHBoxLayout
,
QLabel
)
...
...
@@ -11,27 +11,33 @@ class ToolTip(QFrame):
super
().
__init__
(
parent
=
parent
)
self
.
__text
=
text
self
.
__duration
=
1000
self
.
container
=
QFrame
(
self
)
self
.
timer
=
QTimer
(
self
)
self
.
hBox
=
QHBoxLayout
(
self
)
self
.
setLayout
(
QHBoxLayout
())
self
.
containerLayout
=
QHBoxLayout
(
self
.
container
)
self
.
label
=
QLabel
(
text
,
self
)
self
.
ani
=
QPropertyAnimation
(
self
,
b
'windowOpacity'
,
self
)
# set layout
self
.
hBox
.
addWidget
(
self
.
label
)
self
.
hBox
.
setContentsMargins
(
10
,
7
,
10
,
7
)
self
.
layout
().
setContentsMargins
(
15
,
10
,
15
,
15
)
self
.
layout
().
addWidget
(
self
.
container
)
self
.
containerLayout
.
addWidget
(
self
.
label
)
self
.
containerLayout
.
setContentsMargins
(
10
,
7
,
10
,
7
)
# add shadow
self
.
shadowEffect
=
QGraphicsDropShadowEffect
(
self
)
self
.
shadowEffect
.
setBlurRadius
(
32
)
self
.
shadowEffect
.
setBlurRadius
(
25
)
self
.
shadowEffect
.
setColor
(
QColor
(
0
,
0
,
0
,
60
))
self
.
shadowEffect
.
setOffset
(
0
,
5
)
self
.
setGraphicsEffect
(
self
.
shadowEffect
)
self
.
container
.
setGraphicsEffect
(
self
.
shadowEffect
)
self
.
timer
.
setSingleShot
(
True
)
self
.
timer
.
timeout
.
connect
(
self
.
hide
)
# set style
self
.
setAttribute
(
Qt
.
WA_StyledBackground
)
self
.
setAttribute
(
Qt
.
WA_TranslucentBackground
)
self
.
setWindowFlags
(
Qt
.
Tool
|
Qt
.
FramelessWindowHint
)
self
.
setDarkTheme
(
False
)
self
.
__setQss
()
...
...
@@ -64,7 +70,6 @@ class ToolTip(QFrame):
def
setDarkTheme
(
self
,
dark
=
False
):
""" set dark theme """
dark
=
'true'
if
dark
else
'false'
self
.
setProperty
(
'dark'
,
dark
)
self
.
label
.
setProperty
(
'dark'
,
dark
)
self
.
setStyle
(
QApplication
.
style
())
...
...
@@ -76,4 +81,25 @@ class ToolTip(QFrame):
def
hideEvent
(
self
,
e
):
self
.
timer
.
stop
()
super
().
hideEvent
(
e
)
\ No newline at end of file
super
().
hideEvent
(
e
)
def
adjustPos
(
self
,
pos
:
QPoint
,
size
:
QSize
):
""" adjust the position of tooltip relative to widget
Parameters
----------
pos: QPoint
global position of widget
size: QSize
size of widget
"""
x
=
pos
.
x
()
+
size
.
width
()
//
2
-
self
.
width
()
//
2
y
=
pos
.
y
()
-
self
.
height
()
# adjust postion to prevent tooltips from appearing outside the screen
desk
=
QApplication
.
desktop
()
x
=
min
(
max
(
0
,
x
),
desk
.
width
()
-
self
.
width
()
-
5
)
y
=
min
(
max
(
0
,
y
),
desk
.
height
()
-
self
.
height
()
-
5
)
self
.
move
(
x
,
y
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录