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. Reset the QML Slider value
Qt 6.11 is out! See what's new in the release blog

Reset the QML Slider value

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 839 Views
  • 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
    AROH
    wrote on last edited by
    #1

    Hello,

    I have started practicing the QML since few months, i was unable to figure out a small implementation

    I want to reset the QML slider value to 0 when the user does not drag's the slider handle till the end of the slider (from the below posted code snipped i want to reset the slider handle to 0 if he does not drag till 100).
    I am trying to use the pressed property of slider to reset the handle to value 0 but it is not happening, not getting what i am missing.

    Can someone help with the following code snippet?

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Row {
    
            Slider {
                id:slider
                from: 1
                value: 25
                to: 100
    
                onVisualPositionChanged: {
                    if(slider.pressed != false){
                        console.error("in if===========================",Math.floor(slider.value))
                    }
                    else{
                        slider.value = 0
                    }
                }
            }
    
            Label {
    
                text: Math.floor(slider.value)
            }
        }
    }
    

    Thanks in advance !!

    Regard's,
    #A

    GrecKoG 1 Reply Last reply
    0
    • A AROH

      Hello,

      I have started practicing the QML since few months, i was unable to figure out a small implementation

      I want to reset the QML slider value to 0 when the user does not drag's the slider handle till the end of the slider (from the below posted code snipped i want to reset the slider handle to 0 if he does not drag till 100).
      I am trying to use the pressed property of slider to reset the handle to value 0 but it is not happening, not getting what i am missing.

      Can someone help with the following code snippet?

      import QtQuick 2.9
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Row {
      
              Slider {
                  id:slider
                  from: 1
                  value: 25
                  to: 100
      
                  onVisualPositionChanged: {
                      if(slider.pressed != false){
                          console.error("in if===========================",Math.floor(slider.value))
                      }
                      else{
                          slider.value = 0
                      }
                  }
              }
      
              Label {
      
                  text: Math.floor(slider.value)
              }
          }
      }
      

      Thanks in advance !!

      Regard's,
      #A

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @AROH said in Reset the QML Slider value:

      I want to reset the QML slider value to 0 when the user does not drag's the slider handle till the end of the slider (from the below posted code snipped i want to reset the slider handle to 0 if he does not drag till 100).

      Wouldn't the following do what you want?

      onPressedChanged: {
          if (!pressed && value !== to)
              value = from;
      }
      
      A 1 Reply Last reply
      2
      • A AROH has marked this topic as solved on
      • GrecKoG GrecKo

        @AROH said in Reset the QML Slider value:

        I want to reset the QML slider value to 0 when the user does not drag's the slider handle till the end of the slider (from the below posted code snipped i want to reset the slider handle to 0 if he does not drag till 100).

        Wouldn't the following do what you want?

        onPressedChanged: {
            if (!pressed && value !== to)
                value = from;
        }
        
        A Offline
        A Offline
        AROH
        wrote on last edited by
        #3

        @GrecKo

        Thanks for the inputs.

        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