我正在使用 QtQuick 1.0,我希望 TextInput 元素带有输入以仅获取数字和“.”。要仅获取数字,我使用以下代码:
TextInput {
id: textInput
anchors.centerIn : inputArea
font.family : "Helvetica"
font.pixelSize: textSize
color: "black"
maximumLength: 5
smooth: true
inputMask: "99999"
readOnly: isReadOnly
}
Run Code Online (Sandbox Code Playgroud)
而且我只能输入数字。我应该如何扩展它以获得“。” 还 ?
经过几次运行后,我得出了以下解决方案:
TextInput {
id: textInput
anchors.centerIn : inputArea
font.family : "Helvetica"
font.pixelSize: textSize
color: "black"
maximumLength: 5
smooth: true
validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ }
readOnly: isReadOnly
}
Run Code Online (Sandbox Code Playgroud)