Qt / Qml Quick Control 2:没有数字格式的SpinBox值

时间:2017-08-14 16:51:30

标签: qt qml qtquick2 qtquickcontrols2

我想在没有数字格式的Qml Quick Controls 2 SpinBox中显示数字:

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

我尝试设置不同的区域设置,但每次将数字显示为" 1.000"或" 1,000" (正确的是" 1000")。有没有办法强制无格式输出?

1 个答案:

答案 0 :(得分:3)

您可以覆盖textFromValue功能:

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