-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ShadowEffect.py
70 lines (57 loc) · 2.12 KB
/
ShadowEffect.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年9月25日
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
@email: [email protected]
@file: ShadowEffect
@description:
"""
try:
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit, QApplication
except ImportError:
from PySide2.QtCore import Qt
from PySide2.QtGui import QPixmap
from PySide2.QtWidgets import QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit, QApplication
from Lib.AnimationShadowEffect import AnimationShadowEffect # @UnresolvedImport
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QHBoxLayout(self)
# 绿色边框
labelGreen = QLabel(self, pixmap=QPixmap('Data/1.jpg').scaled(100, 100))
layout.addWidget(labelGreen)
aniGreen = AnimationShadowEffect(Qt.darkGreen, labelGreen)
labelGreen.setGraphicsEffect(aniGreen)
aniGreen.start()
# 红色边框,圆形图片
labelRed = QLabel(self)
labelRed.setMinimumSize(100, 100)
labelRed.setMaximumSize(100, 100)
labelRed.setStyleSheet('border-image: url(Data/1.jpg);border-radius: 50px;')
layout.addWidget(labelRed)
aniRed = AnimationShadowEffect(Qt.red, labelGreen)
labelRed.setGraphicsEffect(aniRed)
aniRed.start()
# 蓝色边框按钮
button = QPushButton('按钮', self)
aniButton = AnimationShadowEffect(Qt.blue, button)
layout.addWidget(button)
button.setGraphicsEffect(aniButton)
button.clicked.connect(aniButton.stop) # 按下按钮停止动画
aniButton.start()
# 青色边框输入框
lineedit = QLineEdit(self)
aniEdit = AnimationShadowEffect(Qt.cyan, lineedit)
layout.addWidget(lineedit)
lineedit.setGraphicsEffect(aniEdit)
aniEdit.start()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())