-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfglobalsearch.py
83 lines (67 loc) · 2.47 KB
/
fglobalsearch.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from .fmoveablewidget import FMoveableWidget
class FGlobalSearchWidget(FMoveableWidget):
style = '''
QFrame#FGlobalSearchWidget{
border: 10px solid rgb(40, 47, 63);
background-color: rgb(40, 47, 63);
}
QLineEdit#search{
border: 2px solid rgb(69, 187, 217);
font: 30px;
color: black;
}
'''
def __init__(self, parent=None):
super(FGlobalSearchWidget, self).__init__(parent)
self.parent = parent
self.setObjectName("FGlobalSearchWidget")
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowFlags(Qt.ToolTip)
self.initData()
self.initUI()
self._initShowAnimation()
self._initHideAnimation()
def initData(self):
pass
def initUI(self):
self.setFixedSize(600, 60)
self.searchEdit = QLineEdit(self)
self.searchEdit.setObjectName("search")
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.searchEdit)
mainLayout.setContentsMargins(0, 0, 0, 0)
mainLayout.setSpacing(0)
self.setLayout(mainLayout)
desktopWidth = QDesktopWidget().availableGeometry().width()
self.move((desktopWidth - self.width()) / 2, 50)
self.setStyleSheet(self.style)
def _initShowAnimation(self):
self.showanimation = QPropertyAnimation(self, b'windowOpacity')
self.showanimation.setStartValue(0)
self.showanimation.setEndValue(1)
self.showanimation.setDuration(1000)
self.showanimation.setEasingCurve(QEasingCurve.OutCubic)
def _initHideAnimation(self):
self.hideanimation = QPropertyAnimation(self, b'windowOpacity')
self.hideanimation.setStartValue(1)
self.hideanimation.setEndValue(0)
self.hideanimation.setDuration(1000)
self.hideanimation.setEasingCurve(QEasingCurve.OutCubic)
self.hideanimation.finished.connect(self.close)
def animationShow(self):
self.show()
self.showanimation.start()
def animationHide(self):
self.hideanimation.start()
def leaveEvent(self, event):
self.setCursor(Qt.ArrowCursor)
def enterEvent(self, event):
self.setCursor(Qt.PointingHandCursor)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.animationHide()