Hi,

sorry i have trouble with my own QDoubleValidator, i set a Range 5-25 but i can't type 15 in to the QLineEdit:
myLineEdit->setValidator(new MyDoubleValidator( 5, 25, 2, myLineEdit));

Can anybody help me?

Greetings,

Whitefurrows

Qt Code:
  1. class MyDoubleValidator : public QDoubleValidator
  2. {
  3. public:
  4. MyDoubleValidator( double bottom, double top, int decimals, QObject* parent = 0)
  5. : QDoubleValidator( bottom, top, decimals, parent){}
  6.  
  7. QValidator::State validate(QString & input, int &) const
  8. {
  9. const double b = bottom();
  10. const double t = top();
  11. const int d = decimals();
  12.  
  13. QRegExp empty(QString::fromLatin1("-?\\.?"));
  14. if (input.contains(' '))
  15. return Invalid;
  16. if (b >= 0 && input.startsWith(QLatin1Char('-')))
  17. return Invalid;
  18. if (empty.exactMatch(input))
  19. return Intermediate;
  20.  
  21. bool ok = false;
  22. double entered = input.toDouble(&ok);
  23. if (!ok) return Invalid;
  24.  
  25. int nume = input.count('e', Qt::CaseInsensitive);
  26.  
  27. int i;
  28. if (input.contains(','))
  29. i = input.indexOf(',');
  30. else
  31. i = input.indexOf('.');
  32.  
  33. if (i >= 0 && nume == 0) {
  34. i++;
  35. int j = i;
  36. while(input[j].isDigit())
  37. j++;
  38. if (j - i > d)
  39. return Invalid;
  40. }
  41.  
  42. if (entered < b || entered > t)
  43. return Invalid;
  44.  
  45. return Acceptable;
  46. }
  47. };
To copy to clipboard, switch view to plain text mode