from PyQt4 import QtGui, QtCore
class CustomLineEdit(QtGui.QLineEdit):
__style = ['', 'QLineEdit { border:1px solid #FF0000;}']
def __init__(self, *args):
QtGui.QLineEdit.__init__(self, *args)
self.__counter = 0
self.__timer = QtCore.QTimer(self)
self.connect(self.__timer, QtCore.SIGNAL('timeout()'), self._timerEvent)
self.setStyleSheet(self.__style[0])
def setErrorState(self, blinkcount = 15, timeout = 200):
self.__counter = blinkcount
self.__timer.start(timeout)
def unsetErrorState(self):
self.__counter = 0
def _timerEvent(self):
if self.__counter != 0: self.__counter -= 1
else: self.__timer.stop()
self.setStyleSheet(self.__style[self.__counter % 2])
app = QtGui.QApplication([])
w = QtGui.QMainWindow()
w.setContentsMargins(5,5,5,5)
l = CustomLineEdit(u'wrong text')
w.setCentralWidget(l)
w.show()
# заданное кол-во раз
QtCore.QTimer.singleShot(2000, l.setErrorState)
# бесконечно, или до принудительного останова
#l.setErrorState(-1)
#QtCore.QTimer.singleShot(10000, l.unsetErrorState)
app.exec_()