1

I want to display numbers in a Qml Quick Controls 2 SpinBox without number formatting:

SpinBox {
    inputMethodHints: Qt.ImhDigitsOnly
    from: 1000
    to: 10000
}

I tried to set different locales but everytime the number is displayed as "1.000" or "1,000" (correct would be "1000"). Is there a way to force the unformatted output?

Hyndrix
  • 4,282
  • 7
  • 41
  • 82
  • For readers that stumble across this question, a related but different question on number formatting for spinboxes: [**How to use Float in a QML SpinBox**](https://stackoverflow.com/questions/43406830/how-to-use-float-in-a-qml-spinbox) – derM - not here for BOT dreams Aug 14 '17 at 21:30

1 Answers1

5

You can override the textFromValue function:

import QtQuick 2.8
import QtQuick.Controls 2.1

ApplicationWindow {
    width: 400
    height: 300
    visible: true

    SpinBox {
        inputMethodHints: Qt.ImhDigitsOnly
        from: 1000
        to: 10000

        textFromValue: function(value) {
            return value;
        }
    }
}
Mitch
  • 23,716
  • 9
  • 83
  • 122