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. QML Gauge. How to make the indicator start from zero

QML Gauge. How to make the indicator start from zero

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 5 Posters 1.1k 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.
  • _ Offline
    _ Offline
    _cocaandcola_
    wrote on last edited by
    #1

    Hello! I have a gauge from -5000 to 5000. Please help me how to make it start filling from zero, not from -5000? At the moment it is filled from -5000 to 1000, and I need it to be from 0 to 1000 for example.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Extras 1.4
    import QtQuick.Extras.Private 1.0
    import QtGraphicalEffects 1.0
    
    Window {
        id: winapp
        visible: true
        width: 1000
        height: 630
        color: "#1b2153"
        title: qsTr("FirstProject")
    
        Gauge {
            id: gauge1
            x: 20
            y: 53
            width: 44
            height: 547
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 30
            value: 1000
            minimumValue: -5000
            maximumValue: 5000
            tickmarkStepSize: 500
            formatValue: function(value) {
                return value.toFixed(0);
            }
        }
    }
    

    Снимок экрана 2020-12-04 в 18.22.45.png

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @_cocaandcola_ said in QML Gauge. How to make the indicator start from zero:

      minimumValue: -5000

      Ummm...

      minimumValue: 0
      

      C++ is a perfectly valid school of magic.

      6thC6 Pradeep P NP 2 Replies Last reply
      0
      • fcarneyF fcarney

        @_cocaandcola_ said in QML Gauge. How to make the indicator start from zero:

        minimumValue: -5000

        Ummm...

        minimumValue: 0
        
        6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #3

        @fcarney
        I laughed. I think what @_cocaandcola_ is chasing though, is a minVal, maxMal AND define the bar using a BarFromVal, BarToVal etc.

        I'd say: Gauge isn't going to suffice. It's not the right tool.
        RangeSlider or make it yourself imo.

        1 Reply Last reply
        1
        • fcarneyF fcarney

          @_cocaandcola_ said in QML Gauge. How to make the indicator start from zero:

          minimumValue: -5000

          Ummm...

          minimumValue: 0
          
          Pradeep P NP Offline
          Pradeep P NP Offline
          Pradeep P N
          wrote on last edited by Pradeep P N
          #4

          Hi @fcarney
          Changing the minimumValue is not a good idea. as it might effect lower limit used by @_cocaandcola_ .

          AFAIK the value always taken from the min value for filling.
          so i would suggest writing a custom one.

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          1 Reply Last reply
          1
          • CharbyC Offline
            CharbyC Offline
            Charby
            wrote on last edited by
            #5

            You can stick with Gauge using style to achieve this...

            import QtQuick 2.12
            import QtQuick.Window 2.12
            import QtQuick.Controls 2.0
            import QtQuick.Controls.Styles 1.4
            import QtQuick.Extras 1.4
            import QtQuick.Extras.Private 1.0
            import QtGraphicalEffects 1.0
            
            Window {
                id: winapp
                visible: true
                width: 1000
                height: 630
                color: "#1b2153"
                title: qsTr("FirstProject")
            
                Gauge {
                    id: gauge1
                    x: 20
                    y: 53
                    width: 44
                    height: 547
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: 30
                    value: 1000
                    minimumValue: -5000
                    maximumValue: 5000
                    tickmarkStepSize: 500
                    formatValue: function(value) {
                        return value.toFixed(0);
                    }
                    property double minBarValue : 0
                    style:GaugeStyle{
                        valueBar: Item {
                             implicitWidth: 16
                             Rectangle{
                                width: parent.width
                                height :(gauge1.value === gauge1.minimumValue) ? 0 : parent.height / (gauge1.value - gauge1.minimumValue) * (gauge1.value - gauge1.minBarValue)
                             }
                         }
                    }
                }
            }
            

            853b2b83-db0a-478a-bd5b-acfffda21394-image.png

            _ 1 Reply Last reply
            2
            • CharbyC Charby

              You can stick with Gauge using style to achieve this...

              import QtQuick 2.12
              import QtQuick.Window 2.12
              import QtQuick.Controls 2.0
              import QtQuick.Controls.Styles 1.4
              import QtQuick.Extras 1.4
              import QtQuick.Extras.Private 1.0
              import QtGraphicalEffects 1.0
              
              Window {
                  id: winapp
                  visible: true
                  width: 1000
                  height: 630
                  color: "#1b2153"
                  title: qsTr("FirstProject")
              
                  Gauge {
                      id: gauge1
                      x: 20
                      y: 53
                      width: 44
                      height: 547
                      anchors.bottom: parent.bottom
                      anchors.bottomMargin: 30
                      value: 1000
                      minimumValue: -5000
                      maximumValue: 5000
                      tickmarkStepSize: 500
                      formatValue: function(value) {
                          return value.toFixed(0);
                      }
                      property double minBarValue : 0
                      style:GaugeStyle{
                          valueBar: Item {
                               implicitWidth: 16
                               Rectangle{
                                  width: parent.width
                                  height :(gauge1.value === gauge1.minimumValue) ? 0 : parent.height / (gauge1.value - gauge1.minimumValue) * (gauge1.value - gauge1.minBarValue)
                               }
                           }
                      }
                  }
              }
              

              853b2b83-db0a-478a-bd5b-acfffda21394-image.png

              _ Offline
              _ Offline
              _cocaandcola_
              wrote on last edited by
              #6

              @Charby Yes it works. However, now if you put value -1000, then the indicator will not show anything

              CharbyC 1 Reply Last reply
              0
              • _ _cocaandcola_

                @Charby Yes it works. However, now if you put value -1000, then the indicator will not show anything

                CharbyC Offline
                CharbyC Offline
                Charby
                wrote on last edited by
                #7

                @_cocaandcola_ I was only showing you an example of using styling to achieve what you are aiming.
                Basically, the idea is replacing the valueBar property of the GaugeStyle which is a Rectangle by default by an Item (so not showing anything) element containing whatever you want within.
                Keeping in mind, the Item size and position is managed by the Gauge ( Item top is the Gauge value and item bottom corresponds to Gauge minimumValue), you can define height and y properties of the child Rectangle to display the bar within the parent Item.

                _ 1 Reply Last reply
                0
                • CharbyC Charby

                  @_cocaandcola_ I was only showing you an example of using styling to achieve what you are aiming.
                  Basically, the idea is replacing the valueBar property of the GaugeStyle which is a Rectangle by default by an Item (so not showing anything) element containing whatever you want within.
                  Keeping in mind, the Item size and position is managed by the Gauge ( Item top is the Gauge value and item bottom corresponds to Gauge minimumValue), you can define height and y properties of the child Rectangle to display the bar within the parent Item.

                  _ Offline
                  _ Offline
                  _cocaandcola_
                  wrote on last edited by
                  #8

                  @Charby thank you very much for your help!!! :)

                  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