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 771B

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