IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QDoubleValidator Class

The https:// class provides range checking of floating-point numbers.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QDoubleValidator Class▲

  • Header: QDoubleValidator

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Gui)

    target_link_libraries(mytarget PRIVATE Qt6::Gui)

  • qmake: QT += gui

  • Inherits: https://

Detailed Description▲

https:// provides an upper bound, a lower bound, and a limit on the number of digits after the decimal point.

You can set the acceptable range in one call with https://(), or with https://() and https://(). Set the number of decimal places with https://(). The https://() function returns the validation state.

https:// uses its https://() to interpret the number. For example, in the German locale, "1,234" will be accepted as the fractional number 1.234. In Arabic locales, https:// will accept Arabic digits.

The https:// set on the https://() also affect the way the number is interpreted. For example, since https:// is not set by default, the validator will accept group separators. It is thus recommended to use https://() to obtain the numeric value.

See Also▲

See also https://, https://, https://(), Line Edits Example

Member Type Documentation▲

 

enum QDoubleValidator::Notation▲

This enum defines the allowed notations for entering a double.

Constant

Value

Description

https://::StandardNotation

0

The string is written as a standard number (i.e. 0.015).

https://::ScientificNotation

1

The string is written in scientific form. It may have an exponent part(i.e. 1.5E-2).

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▲

See also https://()

decimals : int▲

This property holds the validator's maximum number of digits after the decimal point

By default, this property contains a value of -1, which means any number of digits is accepted.

Access functions:

  • int decimals() const

  • void setDecimals(int)

Notifier signal:

  • void decimalsChanged(int decimals)

See Also▲

See also https://()

notation : Notation▲

This property holds the notation of how a string can describe a number

By default, this property is set to https://.

Access functions:

  • notation() const

  • void setNotation(QDoubleValidator::Notation)

Notifier signal:

  • void notationChanged( notation)

See Also▲

See also https://

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▲

See also https://()

Member Function Documentation▲

 

[explicit] 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.

[override virtual, since 6.3] void QDoubleValidator::fixup(QString &input) const▲

Reimplements: https://.

This is an overloaded function.

Attempts to fix the input string to an https:// representation of a double.

The format of the number is determined by https://(), https://(), https://() and the latter's https://().

To comply with https://(), when https:// is used, the fixed value will be represented in its normalized form, which means that any non-zero value will have one non-zero digit before the decimal point.

 
Sélectionnez
QString input = "0.98765e2";
QDoubleValidator val;
val.setLocale(QLocale::C);
val.setNotation(QDoubleValidator::ScientificNotation);
val.fixup(input); // input == "9.8765e+01"

To comply with https://(), when it is -1 the number of digits used will be determined by https://. Otherwise, the fractional part of the number is truncated (with rounding, as appropriate) if its length exceeds https://(). When https://() is https:// this is done after the number has been put into its normalized form.

 
Sélectionnez
input = "-1234.6789";
val.setDecimals(2);
val.setLocale(QLocale::C);
val.setNotation(QDoubleValidator::StandardNotation);
val.fixup(input); // input == "-1234.68"

If https://() is set to, and the string provides, more than std::numeric_limits<double>::digits10, digits beyond that many in the fractional part may be changed. The resulting string shall encode the same floating-point number, when parsed to a double.

This function was introduced in Qt 6.3.

void QDoubleValidator::setRange(double minimum, double maximum, int decimals)▲

Sets the validator to accept doubles from minimum to maximum inclusive, with at most decimals digits after the decimal point.

Setting the number of decimals to -1 effectively sets it to unlimited. This is also the value used by a default-constructed validator.

void QDoubleValidator::setRange(double minimum, double maximum)▲

This is an overloaded function.

Sets the validator to accept doubles from minimum to maximum inclusive without changing the number of digits after the decimal point.

[override virtual] QValidator::State QDoubleValidator::validate(QString &input, int &pos) const▲

Reimplements: https://.

Returns https:// if the string input contains a double that is within the valid range and is in the correct format.

Returns https:// if input contains a double that is outside the range or is in the wrong format; e.g. is empty.

Returns https:// if the input is not a double or with too many digits after the decimal point.

Note: If the valid range consists of just positive doubles (e.g. 0.0 to 100.0) and input is a negative double then https:// is returned. If https://() is set to https://, and the input contains more digits before the decimal point than a double in the valid range may have, https:// is returned. If https://() is https://, and the input is not in the valid range, https:// is returned. The value may yet become valid by changing the exponent.

By default, the pos parameter is not used by this validator.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.