def paintEvent(self, event): super(LineEdit, self).paintEvent(event) painter = QPainter(self) pen = QPen(self.lineHintColor) pen.setWidth(self.borderWidth) painter.setPen(pen) # draw bottom line(画底部横线) #painter.drawLine(self.rect().bottomLeft(), self.rect().bottomRight()) painter.drawLine(0, self.height(), self.width(), self.height()) if not self.isEnabled() or self.isReadOnly(): return LineEffect._paintEvent(self, painter)
def setDisabled(self, enable): super(LineEdit, self).setDisabled(enable) LineEffect._setDisabled(self, enable)
def setReadOnly(self, only): super(LineEdit, self).setReadOnly(only) LineEffect._setEnabled(self, False)
def focusOutEvent(self, event): super(LineEdit, self).focusOutEvent(event) LineEffect._focusOutEvent(self, event)
def __init__(self, *args, **kwargs): super(LineEdit, self).__init__(*args, **kwargs) self.borderWidth = 4 LineEffect.__init__(self) # 去掉边框 self.setFrame(QFrame.NoFrame)