You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qvalidatedlineedit.cpp 751B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "qvalidatedlineedit.h"
  2. QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
  3. QLineEdit(parent), valid(true)
  4. {
  5. connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
  6. }
  7. void QValidatedLineEdit::setValid(bool valid)
  8. {
  9. if(valid == this->valid)
  10. {
  11. return;
  12. }
  13. if(valid)
  14. {
  15. setStyleSheet("");
  16. }
  17. else
  18. {
  19. setStyleSheet("background:#FF8080");
  20. }
  21. this->valid = valid;
  22. }
  23. void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
  24. {
  25. // Clear invalid flag on focus
  26. setValid(true);
  27. QLineEdit::focusInEvent(evt);
  28. }
  29. void QValidatedLineEdit::markValid()
  30. {
  31. setValid(true);
  32. }
  33. void QValidatedLineEdit::clear()
  34. {
  35. setValid(true);
  36. QLineEdit::clear();
  37. }