QDoubleValidator Class
The QDoubleValidator class provides range checking of floating-point numbers. More...
Header: | #include <QDoubleValidator> |
qmake: | QT += gui |
Inherits: | QValidator |
Public Types
enum | Notation { StandardNotation, ScientificNotation } |
Properties
- 1 property inherited from QObject
Public Functions
QDoubleValidator(QObject *parent = nullptr) | |
QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr) | |
virtual | ~QDoubleValidator() |
double | bottom() const |
int | decimals() const |
QDoubleValidator::Notation | notation() const |
void | setBottom(double) |
void | setDecimals(int) |
void | setNotation(QDoubleValidator::Notation) |
virtual void | setRange(double minimum, double maximum, int decimals = 0) |
void | setTop(double) |
double | top() const |
Reimplemented Public Functions
virtual QValidator::State | validate(QString &, int &) const override |
- 4 public functions inherited from QValidator
- 34 public functions inherited from QObject
Signals
void | bottomChanged(double bottom) |
void | decimalsChanged(int decimals) |
void | notationChanged(QDoubleValidator::Notation notation) |
void | topChanged(double top) |
- 1 signal inherited from QValidator
- 2 signals inherited from QObject
Additional Inherited Members
- 1 public slot inherited from QObject
- 1 public variable inherited from QObject
- 10 static public members inherited from QObject
- 9 protected functions inherited from QObject
- 2 protected variables inherited from QObject
Detailed Description
The QDoubleValidator class provides range checking of floating-point numbers.
QDoubleValidator provides an upper bound, a lower bound, and a limit on the number of digits after the decimal point. It does not provide a fixup() function.
You can set the acceptable range in one call with setRange(), or with setBottom() and setTop(). Set the number of decimal places with setDecimals(). The validate() function returns the validation state.
QDoubleValidator uses its locale() to interpret the number. For example, in the German locale, "1,234" will be accepted as the fractional number 1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
Note: The QLocale::NumberOptions set on the locale() also affect the way the number is interpreted. For example, since QLocale::RejectGroupSeparator is not set by default, the validator will accept group separators. It is thus recommended to use QLocale::toDouble() to obtain the numeric value.
See also QIntValidator, QRegExpValidator, QLocale::toDouble(), and Line Edits Example.
Member Type Documentation
enum QDoubleValidator::Notation
This enum defines the allowed notations for entering a double.
Constant | Value | Description |
---|---|---|
QDoubleValidator::StandardNotation | 0 | The string is written as a standard number (i.e. 0.015). |
QDoubleValidator::ScientificNotation | 1 | The string is written in scientific form. It may have an exponent part(i.e. 1.5E-2). |
This enum was introduced or modified in Qt 4.3.
Property Documentation
bottom : double
This property holds the validator's minimum acceptable value
By default, this property contains a value of -infinity.
Access functions:
double | bottom() const |
void | setBottom(double) |
Notifier signal:
void | bottomChanged(double bottom) |
See also setRange().
decimals : int
This property holds the validator's maximum number of digits after the decimal point
By default, this property contains a value of 1000.
Access functions:
int | decimals() const |
void | setDecimals(int) |
Notifier signal:
void | decimalsChanged(int decimals) |
See also setRange().
notation : Notation
This property holds the notation of how a string can describe a number
By default, this property is set to ScientificNotation.
This property was introduced in Qt 4.3.
Access functions:
QDoubleValidator::Notation | notation() const |
void | setNotation(QDoubleValidator::Notation) |
Notifier signal:
void | notationChanged(QDoubleValidator::Notation notation) |
See also Notation.
top : double
This property holds the validator's maximum acceptable value
By default, this property contains a value of infinity.
Access functions:
double | top() const |
void | setTop(double) |
Notifier signal:
void | topChanged(double top) |
See also setRange().
Member Function Documentation
QDoubleValidator::QDoubleValidator(QObject *parent = nullptr)
Constructs a validator object with a parent object that accepts any double.
QDoubleValidator::QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr)
Constructs a validator object with a parent object. This validator will accept doubles from bottom to top inclusive, with up to decimals digits after the decimal point.
[virtual]
QDoubleValidator::~QDoubleValidator()
Destroys the validator.
[virtual]
void QDoubleValidator::setRange(double minimum, double maximum, int decimals = 0)
Sets the validator to accept doubles from minimum to maximum inclusive, with at most decimals digits after the decimal point.