DoubleValidator QML Type
定义了一个用于非整数类型的验证器。更多...
| Import Statement: | import QtQuick |
| In C++: | QDoubleValidator |
属性
详细说明
DoubleValidator 类型为非整数提供了验证器。
- 接受的输入:如果输入包含一个在有效范围内且格式正确的双精度数值,则该输入被接受。
- 接受但无效的输入:如果输入包含超出有效范围或格式错误(例如小数点后位数过多或为空)的 double 类型数值,则该输入被接受但被视为无效。
- 被拒绝的输入:如果输入不是双精度浮点数,则被拒绝。
注意:如果 有效范围仅包含正双精度数值(例如 0.0 到 100.0),而输入为负双精度数值,则该输入将被拒绝。如果将 `notation ` 设置为 `DoubleValidator.StandardNotation `,且输入的小数点前位数多于有效范围内的双精度数值所能包含的位数,该输入也将被拒绝。 如果notation 设置为DoubleValidator.ScientificNotation ,且输入值不在有效范围内,则该输入会被接受但标记为无效。通过更改指数,该值可能变为有效。
以下示例展示了一个带有 DoubleValidator 的TextInput 对象,用于检查用户输入的双精度数值是否在指定范围内,并更新文本颜色以突出显示无效输入:
import QtQuick
TextInput {
focus: true
validator: DoubleValidator {
bottom: 0.00
top: 100.00
decimals: 2
notation: DoubleValidator.StandardNotation
}
onAcceptableInputChanged:
color = acceptableInput ? "black" : "red";
}另请参阅 IntValidator 、RegularExpressionValidator 以及《验证输入文本》。
属性文档
bottom : real
该属性存储验证器的最小可接受值。默认情况下,该属性的值为 -infinity。
decimals : int
该属性用于指定验证器允许的小数点后最大位数。默认情况下,该属性的值为 1000。
locale : string
该属性存储用于解析该数字的区域设置名称。
另请参阅 Qt.locale()。
notation : enumeration
该属性用于指定字符串如何表示一个数字。
该属性的可能取值为:
| 常量 | 描述 |
|---|---|
DoubleValidator.StandardNotation | 仅限带可选正负号的十进制数(例如:-0.015 ) |
DoubleValidator.ScientificNotation | (默认)所写的数字可以包含指数部分(例如:1.5E-2 ) |
top : real
该属性存储了验证器可接受的最大值。默认情况下,该属性的值为无穷大。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.