-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathTestToolTip.py
63 lines (52 loc) · 1.82 KB
/
TestToolTip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年1月2日
@author: Irony
@site: https://pyqt.site https://github.com/PyQt5
@email: 892768447@qq.com
@file: Test.TestToolTip
@description:
"""
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QWidget
from Widgets.ToolTip import ToolTip
class TestWindow(QWidget):
def __init__(self, *args, **kwargs):
super(TestWindow, self).__init__(*args, **kwargs)
self.resize(600, 400)
layout = QHBoxLayout(self)
btn1 = QPushButton('鼠标悬停1', self, minimumHeight=38, toolTip='这是按钮1')
ToolTip.bind(btn1)
layout.addWidget(btn1)
btn2 = QPushButton('鼠标悬停2', toolTip='这是按钮2')
ToolTip.bind(btn2)
layout.addWidget(btn2)
def showEvent(self, event):
super(TestWindow, self).showEvent(event)
if not hasattr(self, '_tip'):
def test():
self._tip = ToolTip()
self._tip.setText('底部居中提示')
self._tip.show()
self._tip.move(
self.pos().x() + int(
(self.width() - self._tip.width()) / 2),
self.pos().y() + self.height() - 20,
)
self._tip._hideTimer.timeout.connect(self._tip.close)
self._tip._hideTimer.start(2000)
QTimer.singleShot(1000, test)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QPushButton
app = QApplication(sys.argv)
app.setStyleSheet("""ToolTip > QLabel {
color: white;
border-radius: 5px;
padding: 10px;
background-color: rgba(77, 77, 77, 180);
}""")
w = TestWindow()
w.show()
sys.exit(app.exec_())