Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-94271

inaccurate value on Slider and RangeSlider

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.9.0
    • Quick: Controls 2
    • None

    Description

      Slider and RangeSlider in Controls 2 get inaccurate value when it is used in below cases.

       

      // Slider
      Slider {
          from: -10
          to: 10
          stepSize: 0.1
          snapMode: Slider.SnapAlways
          onValueChanged: {
              console.log(value)
          }
      }
      

       

      I expect the value changes like ... -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3 ...

      but actual result is like this.

       

      qml: 1.1000000000000014
      qml: 1.3000000000000007
      qml: 1.4000000000000004
      qml: 1.5
      qml: 1.6000000000000014
      qml: 1.8000000000000007
      qml: 1.9000000000000004
      qml: 2
      qml: 2.1000000000000014
      qml: 2.3000000000000007
      

       

       I know that the native logic is performing decimal operations using internal position value between 0.0 ~ 1.0, then the result of decimal operation can be like that.

      Nevertheless,  Slider is providing a stepSize property that means the value will be changed at given stepSize gaps and also a user is expecting discrete value according to the stepSize.
      It feels like an inaccurate value. If the stepSize is given, the lower decimal places than the stepSize's decimal places should be eliminated. 
       

      The same problem occurs at RangeSlider. 

       

      // RangeSlider
      RangeSlider {
          from: -30
          to: 30 
          stepSize: 10
          first.value: -10
          second.value: 10
          snapMode: RangeSlider.SnapAlways
          first.onValueChanged: {
              console.log(first.value)
          }
          second.onValueChanged: {
              console.log(second.value)
          }
      }
      

      the results are below. we expect the value changes like 10, 20, 30 but

      qml: 10
      qml: 19.999999999999993
      qml: 30
      qml: 19.999999999999993
      qml: 10
      

       

      I think "valueAt" function in qquickslider.cpp, qquickrangeslider.cpp needs to be modified so that stepSize property can be considered.

       

       

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-94271
          # Subject Branch Project Status CR V

          Activity

            People

              michael.s Michael Szczerba
              sukyoungoh Oh Sukyoung
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change