DoubleValidator QML Type
定义非整数的验证器。更多
Import Statement: | import QtQuick |
In C++: | QDoubleValidator |
属性
详细说明
DoubleValidator 类型为非整数提供了一个验证器。
- 接受输入:如果输入的数字在有效范围内,且格式正确,则输入将被接受。
- 接受但无效的输入:如果输入超出有效范围或格式错误(例如,小数点后数字过多或为空),则输入被接受,但视为无效。
- 拒绝输入:如果输入内容不是双倍值,则会被拒绝。
注意: 如果有效范围只包括正二进制(例如 0.0 到 100.0),而输入是负二进制,则会被拒绝。如果notation 设置为DoubleValidator.StandardNotation
,而输入内容在小数点前的位数超过了有效范围内的双倍数,也会被拒绝。如果notation 设置为DoubleValidator.ScientificNotation
,而输入值不在有效范围内,则该值被接受但无效。更改指数后,该值可能会变成有效值。
下面的示例显示了一个带有 DoubleValidator 的TextInput 对象,用于检查用户是否在指定范围内输入了一个 double,并更新文本颜色以突出显示无效输入:
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。
notation : enumeration |
该属性包含字符串描述数字的符号。
该属性的可能值有
常量 | 描述 |
---|---|
DoubleValidator.StandardNotation | 仅十进制数,带可选符号(如-0.015 ) |
DoubleValidator.ScientificNotation | (默认)写入的数字可以有指数部分(例如:1.5E-2 ) |
top : real |
该属性包含验证器可接受的最大值。默认情况下,该属性的值为无穷大。
© 2025 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.