自定义QML部件SpinBox

版本:Qt5.12

由于QT官方提供的SpinBox部件,需要确认时才能更新里面数据,所以才自定义。 

import QtQuick 2.12
import QtQuick.Controls 2.12

SpinBox{
    id:spinboxID
    height: parent.height
    width:parent.width-title_input.width-image_input.height-20
    anchors.left : title_input.right
    anchors.leftMargin:10
    editable : true
    contentItem: TextInput {
            z: 2
            text: spinboxID.textFromValue(spinboxID.value, spinboxID.locale)
            font: spinboxID.font
            color:spinboxID.enabled?"#111":"#bbb"
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter

            readOnly: !spinboxID.editable
            validator: spinboxID.validator
            inputMethodHints: Qt.ImhFormattedNumbersOnly
            onTextChanged: {
                var textreg = text.replace(/[^-0-9]/ig,"");
                  spinboxID.value= Number.fromLocaleString( spinboxID.locale,textreg);
            }
        }
}

 

你可能感兴趣的:(QML)