DoubleSpinBox QML Type
允许用户从一组预设的浮点数值中进行选择。更多...
| Import Statement: | import QtQuick.Controls |
| Since: | Qt 6.11 |
| Inherits: |
属性
- decimals : int
- displayText : string
- down
- down.hovered : bool
- down.implicitIndicatorHeight : real
- down.implicitIndicatorWidth : real
- down.indicator : Item
- down.pressed : bool
- editable : bool
- from : double
- inputMethodComposing : bool
- inputMethodHints : flags
(since QtQuick.Controls 2.2 (Qt 5.9)) - stepSize : double
- textFromValue : function
- to : double
- up
- up.hovered : bool
- up.implicitIndicatorHeight : real
- up.implicitIndicatorWidth : real
- up.indicator : Item
- up.pressed : bool
- validator : Validator
- value : double
- valueFromText : function
- wrap : bool
(since QtQuick.Controls 2.3 (Qt 5.10))
信号
方法
详细说明

DoubleSpinBox 与SpinBox 类似,不同之处在于它支持双精度值而非整数。用户可以通过点击上/下指示按钮,或使用键盘上的上/下方向键来选择数值。此外,DoubleSpinBox 还可以设置为editable ,这样用户便可以在输入框中输入文本值。
默认情况下,DoubleSpinBox 提供的离散值范围与[0.00-99.99] 相同,且其stepSize 为1.0 。
DoubleSpinBox {
id: doubleSpinBox
from: 0
value: 1.1
to: 100
stepSize: Math.pow(10, -decimals)
decimals: 2
editable: true
anchors.centerIn: parent
}另请参阅 SpinBox 、Tumbler 、自定义 DoubleSpinBox 以及 Qt Quick Controls 中的焦点管理。
属性文档
decimals : int
该属性控制旋转输入框在显示和解析双精度数值时所使用的有效数字位数。
默认值为2 。
警告: 由于 double 类型的限制,decimals 的最大值为 DBL_MAX_10_EXP + DBL_DIG (323 )。
displayText : string [read-only]
该属性保存旋转框的文本值。
该属性的值基于textFromValue 和locale ,其定义如下:
let text = spinBox.textFromValue(spinBox.value, spinBox.decimals, spinBox.locale)另请参阅 textFromValue 。
down group
down.hovered : bool
down.implicitIndicatorHeight : real
down.implicitIndicatorWidth : real
down.indicator : Item
down.pressed : bool
此分组属性包含“向下”指示器项及其相关属性。
另请参阅 decrease()。
editable : bool
该属性用于指定旋转框是否可编辑。默认值为false 。
另请参阅 validator 。
from : double
该属性存储范围的起始值。默认值为0.0 。
inputMethodComposing : bool [read-only]
该属性用于指示可编辑的旋转框是否已通过输入法接收了部分文本输入。
在输入过程中,输入法可能会依赖来自旋转输入框的鼠标或键盘事件来编辑或提交部分文本。该属性可用于确定何时禁用可能干扰输入法正常运行的事件处理程序。
inputMethodHints : flags [since QtQuick.Controls 2.2 (Qt 5.9)]
该属性向输入法提供关于旋转框预期内容及其工作方式的提示。
默认值为Qt.ImhDigitsOnly 。
该值是标志位的按位组合,若未设置提示,则为Qt.ImhNone 。
可改变行为的标志包括:
- Qt.ImhHiddenText - 字符应被隐藏,这通常用于输入密码时。
- Qt.ImhSensitiveData - 活动输入法不应将输入的文本存储在任何持久存储中,例如预测性用户词典。
- Qt.ImhNoAutoUppercase - 当句子结束时,输入法不应尝试自动切换为大写。
- Qt.ImhPreferNumbers - 优先使用数字(但非强制要求)。
- Qt.ImhPreferUppercase - 优先使用大写字母(但非强制要求)。
- Qt.ImhPreferLowercase - 优先使用小写字母(但不是必须的)。
- Qt.ImhNoPredictiveText - 输入时不使用预测文本(即词典查找)。
- Qt.ImhDate - 文本编辑器作为日期字段使用。
- Qt.ImhTime - 文本编辑器作为时间字段使用。
限制输入的标志(排他标志)包括:
- Qt.ImhDigitsOnly - 仅允许输入数字。
- Qt.ImhFormattedNumbersOnly - 仅允许输入数字。这包括小数点和负号。
- Qt.ImhUppercaseOnly - 仅允许输入大写字母。
- Qt.ImhLowercaseOnly - 仅允许输入小写字母。
- Qt.ImhDialableCharactersOnly - 仅允许输入适用于电话拨号的字符。
- Qt.ImhEmailCharactersOnly - 仅允许输入适合电子邮件地址的字符。
- Qt.ImhUrlCharactersOnly - 仅允许输入适用于 URL 的字符。
掩码:
- Qt.ImhExclusiveInputMask - 若使用了任何排他标志,此掩码将返回非零值。
该属性于 QtQuick.Controls 2.2(Qt 5.9)中引入。
stepSize : double
该属性存储步长。默认值为1.0 。
textFromValue : function
该属性保存了一个回调函数,每当需要将双精度值转换为显示文本时,该函数就会被调用。
可以重写默认函数,以便针对特定值显示自定义文本。这适用于可编辑和不可编辑的旋转框;例如,当使用上下按钮或鼠标滚轮增减数值时,新值会通过此函数转换为显示文本。
回调函数的签名是string function(value, decimals, locale) 。该函数可包含两个或三个参数,其中第一个参数是要转换的值,第二个参数是小数位数,可选的第三个参数是转换时应使用的区域设置(如适用)。
默认实现使用Number.toLocaleString() 进行转换:
textFromValue: function(value, decimals, locale) {
return Number(value).toLocaleString(locale, 'f', decimals);
}注意:当 为可编辑的旋转框应用自定义的textFromValue 实现时 ,必须提供相应的valueFromText 实现,以便将自定义文本转换回 double 值。
另请参阅 valueFromText 、validator 和locale 。
to : double
该属性存储了范围的结束值。默认值为99.99 。
up group
up.hovered : bool
up.implicitIndicatorHeight : real
up.implicitIndicatorWidth : real
up.indicator : Item
up.pressed : bool
该分组属性包含“向上”指示器项及其相关属性。
另请参阅 increase()。
validator : Validator
该属性用于设置可编辑旋转框的输入文本验证器。默认情况下,DoubleSpinBox 使用DoubleValidator 来接受双精度数值输入。
DoubleSpinBox {
id: control
validator: DoubleValidator {
locale: control.locale.name
bottom: Math.min(control.from, control.to)
top: Math.max(control.from, control.to)
}
}另请参阅 editable 、textFromValue 、valueFromText 、locale 以及《输入文本验证》。
value : double
该属性的取值范围为from -to 。默认值为0.0 。
valueFromText : function
该属性保存一个回调函数,每当需要将输入文本转换为双精度值时,该函数就会被调用。
仅当为可编辑的旋转框重写 `textFromValue ` 时,才需要重写此函数。
回调函数的签名是 `int function(text, locale)`。该函数可以有一个或两个参数,其中第一个参数是要转换的文本,可选的第二个参数是转换时应使用的区域设置(如适用)。
默认实现使用Number.fromLocaleString() 进行转换:
valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text); }注意:当 为可编辑的旋转输入框应用自定义的textFromValue 实现时 ,必须提供相应的valueFromText 实现,以便将自定义文本转换回 double 类型值。
另请参阅 textFromValue 、validator 和locale 。
wrap : bool [since QtQuick.Controls 2.3 (Qt 5.10)]
该属性控制自旋框是否换行。默认值为false 。
如果 wrap 的值为 `true`,则当值超过 `to ` 时,数值将变为 `from `,反之亦然。
该属性在 QtQuick.Controls 2.3(Qt 5.10)中引入。
信号文档
valueModified()
当用户通过触摸、鼠标、滚轮或键盘交互式地修改了下拉框的值时,会发出此信号。如果是通过键盘进行交互,则只有在文本被接受时才会发出该信号;也就是说,当按下回车键或输入字段失去焦点时。
注意: 相应的处理程序 是onValueModified 。
方法文档
void decrease()
将该值减去stepSize ;如果未定义stepSize ,则减去1 。
另请参阅 stepSize 。
void increase()
将该值增加stepSize ;如果未定义stepSize ,则增加1 。
另请参阅 stepSize 。
© 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.