Search code examples
qtqmlqtquick2qtquickcontrols2

Qt/Qml Quick Control 2: SpinBox value without number format


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?


Solution

  • 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;
            }
        }
    }