Link Slider and TextInput values together



  • Hi,
    i m new at QtQuick so i have some "little problem". I want an editable area to type a float from -10 to 10 with 2 digits only. I want the slider to move when i type the number or if i want to use the slider instead of the text edit, i want the text edit to change too.
    With this code, if i move the slider it works, and when i type on textinput it doesn't block me when i try to go out of scope.
    I don't like my code very much so many there is another way to do this (there are some errors at begininng.
    Thanks

    @import QtQuick 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.1

    Rectangle {
    property real value : parseFloat(an.text)
    property alias text : texte.text

    RowLayout {
        anchors.fill: parent
        width: 200
        height: 40
        Text {
            id: texte
            //width: 80
            height: 20
            font.pixelSize: 12
        }
    
        TextInput {
            id: an
            text: value
            clip: true
            validator: DoubleValidator {bottom: -10; top: 10; decimals: 2}
            onTextChanged: value=parseFloat(text)
        }
    
        Slider {
            id: slider
            minimumValue: -10
            maximumValue: 10
            stepSize: 0.1
            value: value
            Layout.fillWidth: true
            onValueChanged: parent.parent.value=value==null?0:Math.floor(value*100)/100
        }
    }
    onValueChanged: {
                    slider.value=value
                    console.log("value changed : "+value)
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.