OGS
StrictIntValidator.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <QIntValidator>
18 
24 class StrictIntValidator : public QIntValidator
25 {
26 public:
27  StrictIntValidator(int min, int max, QObject* parent = nullptr)
28  : QIntValidator(min, max, parent)
29  {
30  }
31 
32  QValidator::State validate(QString& input, int& pos) const override
33  {
34  if (input.isEmpty())
35  return Intermediate;
36 
37  if (QIntValidator::validate(input, pos) != Acceptable)
38  return Invalid;
39  return Acceptable;
40  }
41 };
A validator for an input field which only accepts integers. Source code adapted from Qt developer faq...
QValidator::State validate(QString &input, int &pos) const override
StrictIntValidator(int min, int max, QObject *parent=nullptr)