blob: 4db50812103ccb7746e931074b6b8c7886c56bd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
//! [1]
SpinBox {
id: spinBox
from: 0
value: 11
to: 100
editable: true
anchors.centerIn: parent
property string prefix: "L="
property string suffix: "m"
validator: RegularExpressionValidator { regularExpression: /\D*(-?\d*\.?\d*)\D*/ }
textFromValue: function(value, locale) {
return prefix + Number(value).toLocaleString(locale, 'f', 0) + suffix
}
valueFromText: function(text, locale) {
let re = /\D*(-?\d*\.?\d*)\D*/
return Number.fromLocaleString(locale, re.exec(text)[1])
}
}
//! [1]
|