QLineEdit边框闪烁
源码
from PyQt5 import QtCore
from PyQt5.QtCore import QPropertyAnimation, pyqtProperty
from PyQt5.QtWidgets import QMainWindow, QApplication, QLineEdit
from PyQt5 import QtWidgetsclass NewLineEdit(QLineEdit):
def __init__(self, parent=None):
super(NewLineEdit, self).__init__(parent)def _set_color(self, value):
color = 'border: 1px solid rgba(255, 0, 0, %s);
' % value
self.setStyleSheet(color)color = pyqtProperty(int, fset=_set_color)class Form(QMainWindow):
def __init__(self):
super(Form, self).__init__()
self.setupUi()self.pushButton.clicked.connect(self.pushButton_clicked)def pushButton_clicked(self):
self.animation = QPropertyAnimation(self.lineEdit, b'color')
self.animation.setDuration(200)
self.animation.setLoopCount(3)
self.animation.setStartValue(255)
self.animation.setKeyValueAt(0.5, 0)
self.animation.setEndValue(255)
self.animation.start()def setupUi(self):
self.resize(400, 300)
self.centralwidget = QtWidgets.QWidget(self)
self.lineEdit = NewLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(160, 100, 113, 20))
self.pushButton = QtWidgets.QPushButton('pushbutton', self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(50, 100, 75, 23))
self.setCentralWidget(self.centralwidget)if __name__ == '__main__':
import sysapp = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
截图 【QLineEdit边框闪烁】

文章图片
推荐阅读
- CSS揭秘(过渡和动画实用技巧——弹跳、闪烁、打字动画)
- CSS揭密(背景和边框特殊技巧)
- web前端|CSS科技感四角边框
- android|android shape实现边框圆角
- 问题解决|[已解决]Databinding和RecycleView使用时,界面闪烁,项目状态更新混乱
- Flutter 运行项目边框出现绿色的框框包围
- CSS3边框样式|CSS3边框样式 圆角、边框图片、边框阴影-来自三人行慕课
- el-button type=text 文字按钮 边框去除和添加
- C语言实现一个闪烁的圣诞树
- Winform自定义控件在界面拖动、滚动鼠标时闪烁的解决方法