PyQt/QGraphicsDropShadowEffect/ShadowEffect.py

71 lines
2.1 KiB
Python
Raw Permalink Normal View History

2018-09-25 23:31:08 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年9月25日
@author: Irony
2021-07-13 14:52:26 +08:00
@site: https://pyqt.site , https://github.com/PyQt5
2018-09-25 23:31:08 +08:00
@email: 892768447@qq.com
2018-12-28 23:09:46 +08:00
@file: ShadowEffect
2018-09-25 23:31:08 +08:00
@description:
"""
2021-07-13 14:52:26 +08:00
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
2018-09-25 23:31:08 +08:00
2021-07-13 14:52:26 +08:00
from Lib.AnimationShadowEffect import AnimationShadowEffect # @UnresolvedImport
2018-09-25 23:31:08 +08:00
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QHBoxLayout(self)
# 绿色边框
2018-12-28 23:09:46 +08:00
labelGreen = QLabel(self, pixmap=QPixmap('Data/1.jpg').scaled(100, 100))
2018-09-25 23:31:08 +08:00
layout.addWidget(labelGreen)
aniGreen = AnimationShadowEffect(Qt.darkGreen, labelGreen)
labelGreen.setGraphicsEffect(aniGreen)
aniGreen.start()
# 红色边框,圆形图片
labelRed = QLabel(self)
labelRed.setMinimumSize(100, 100)
labelRed.setMaximumSize(100, 100)
2018-12-28 23:09:46 +08:00
labelRed.setStyleSheet('border-image: url(Data/1.jpg);border-radius: 50px;')
2018-09-25 23:31:08 +08:00
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)
2018-09-26 16:24:32 +08:00
button.clicked.connect(aniButton.stop) # 按下按钮停止动画
2018-09-25 23:31:08 +08:00
aniButton.start()
# 青色边框输入框
lineedit = QLineEdit(self)
aniEdit = AnimationShadowEffect(Qt.cyan, lineedit)
layout.addWidget(lineedit)
lineedit.setGraphicsEffect(aniEdit)
aniEdit.start()
if __name__ == '__main__':
import sys
2021-07-13 14:52:26 +08:00
2018-09-25 23:31:08 +08:00
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())