diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-14 21:06:10 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-11-14 21:06:10 +0100 |
| commit | a24bb7cb1e2e25805243ce6d63dbc42cbce836ae (patch) | |
| tree | 1c16031f36a1ff4a779019b7c870c1754e10f12e /DoubleSpinBox.qml | |
| parent | 3a0137b045c817516b2341931ad9128fa70a1fd5 (diff) | |
adopt new params; introduce ugly DoubleSpinBox
Diffstat (limited to 'DoubleSpinBox.qml')
| -rw-r--r-- | DoubleSpinBox.qml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/DoubleSpinBox.qml b/DoubleSpinBox.qml new file mode 100644 index 0000000..8a86e89 --- /dev/null +++ b/DoubleSpinBox.qml @@ -0,0 +1,35 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material + +SpinBox { + id: spinBox + from: 0 + // value: decimalToInt(1.1) + to: decimalToInt(100) + stepSize: decimalFactor + editable: true + + property int decimals: 2 + property real realValue: value / decimalFactor + readonly property int decimalFactor: Math.pow(10, decimals) + + function decimalToInt(decimal) { + return decimal * decimalFactor + } + + validator: DoubleValidator { + bottom: Math.min(spinBox.from, spinBox.to) + top: Math.max(spinBox.from, spinBox.to) + decimals: spinBox.decimals + notation: DoubleValidator.StandardNotation + } + + textFromValue: function(value, locale) { + return Number(value / decimalFactor).toLocaleString(locale, 'f', spinBox.decimals) + } + + valueFromText: function(text, locale) { + return Math.round(Number.fromLocaleString(locale, text) * decimalFactor) + } +} |
