Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Link Slider and TextInput values together
Forum Updated to NodeBB v4.3 + New Features

Link Slider and TextInput values together

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 750 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    archqt
    wrote on last edited by
    #1

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

    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved