QDoubleValidator 类

QDoubleValidator 类为浮点数提供范围校验。 更多...

头: #include <QDoubleValidator>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QValidator

公共类型

enum Notation { StandardNotation, ScientificNotation }

特性

公共函数

  QDoubleValidator (double bottom , double top , int decimals , QObject * parent = nullptr)
  QDoubleValidator (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)
void setRange (double minimum , double maximum , int decimals = 0)
void setTop (double)
double top () const

重实现公共函数

virtual QValidator::State validate (QString & input , int & pos ) const override

信号

void bottomChanged (double bottom )
void decimalsChanged (int decimals )
void notationChanged (QDoubleValidator::Notation notation )
void topChanged (double top )

详细描述

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 () 函数。

You can set the acceptable range in one call with setRange (), or with setBottom () 和 setTop (). Set the number of decimal places with setDecimals ()。 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.

注意: QLocale::NumberOptions 设置在 locale () 还会影响数字的解释方式。例如,由于 QLocale::RejectGroupSeparator 默认未设置,验证器将接受组分隔符。因此推荐使用 QLocale::toDouble () 获得数值。

另请参阅 QIntValidator , QRegularExpressionValidator , QLocale::toDouble (),和 行编辑范例 .

成员类型文档编制

enum QDoubleValidator:: Notation

This enum defines the allowed notations for entering a double.

常量 描述
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).

特性文档编制

bottom : double

This property holds the validator's minimum acceptable value

By default, this property contains a value of -infinity.

访问函数:

double bottom () const
void setBottom (double)

通知程序信号:

void bottomChanged (double bottom )

另请参阅 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.

访问函数:

int decimals () const
void setDecimals (int)

通知程序信号:

void decimalsChanged (int decimals )

另请参阅 setRange ().

notation : Notation

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

默认情况下,此特性被设为 ScientificNotation .

访问函数:

QDoubleValidator::Notation notation () const
void setNotation (QDoubleValidator::Notation)

通知程序信号:

void notationChanged (QDoubleValidator::Notation notation )

另请参阅 Notation .

top : double

This property holds the validator's maximum acceptable value

By default, this property contains a value of infinity.

访问函数:

double top () const
void setTop (double)

通知程序信号:

void topChanged (double top )

另请参阅 setRange ().

成员函数文档编制

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.

QDoubleValidator:: QDoubleValidator ( QObject * parent = nullptr)

Constructs a validator object with a parent object that accepts any double.

[虚拟] QDoubleValidator:: ~QDoubleValidator ()

销毁验证器。

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.

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

重实现: QValidator::validate (QString &input, int &pos) const.

返回 Acceptable 若字符串 input contains a double that is within the valid range and is in the correct format.

返回 中间体 if input contains a double that is outside the range or is in the wrong format; e.g. is empty.

返回 Invalid 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 Invalid 被返回。若 notation () 被设为 StandardNotation , and the input contains more digits before the decimal point than a double in the valid range may have, Invalid 被返回。若 notation () 是 ScientificNotation , and the input is not in the valid range, 中间体 is returned. The value may yet become valid by changing the exponent.

默认情况下, pos 参数并未用于此验证器。