The maximum value that a gauge can accept



  • what is the the maximum value that a gauge can accept, because when i use this values the application crash!
    Thanks in advance

    Rectangle {
            width: 50
            height: 300
            anchors.centerIn: parent
            color: "transparent"
            property alias gauge: gauge_act_1
            Gauge {
                id: gauge_act_1
                maximumValue: 481900
                minimumValue: 357100
                value: 410841
                font.pixelSize: 9
                anchors.centerIn: parent
                anchors.leftMargin: 2
                anchors.rightMargin: 2
                formatValue: function(value) {
                    return value.toFixed(1);
                }            
    
                style: GaugeStyle {
    
                    valueBar: Rectangle {
                        color: "#FF003399"
                        implicitWidth: 15
                    }
                }
                objectName: "gauge_act_1"
            }
        }
    


  • @halima

    Your problem is not due to the maximum value but the step between each value. By default the step is 10 I let you do the count but it is way to many tick marks to put on the screen.

    Here the doc : tickMarkStepSize

    Try this code :

        Rectangle {
                width: 50
                height: 300
                anchors.centerIn: parent
                color: "transparent"
                property alias gauge: gauge_act_1
                Gauge {
                    id: gauge_act_1
                    maximumValue: 481900
                    minimumValue: 357100
                    tickmarkStepSize : 10000  //This is what is going to help you here
                    value: 410841
                    font.pixelSize: 9
                    anchors.centerIn: parent
                    anchors.leftMargin: 2
                    anchors.rightMargin: 2
                    formatValue: function(value) {
                        return value.toFixed(1);
                    }
    
                    style: GaugeStyle {
    
                        valueBar: Rectangle {
                            color: "#FF003399"
                            implicitWidth: 15
                        }
                    }
                    objectName: "gauge_act_1"
                }
            }
    

    You probably don't need this anymore :

     formatValue: function(value) {
                        return value.toFixed(1);
                    }
    

    Because you are using int values.

    0_1531305036646_3eaadae3-dcde-48b0-b0b3-5f7f0339a310-image.png



  • @DavidM29
    thanks for your answer it helped me a lot! I used int values for test only but normally i use doubles.
    I do not preside the tickMarkStepSize value because the max and min are dynamic values.
    Do you have an idea to calculate the tickMarkStepSize using the max and min without giving a fixed value .
    I use this formula for the moment I do not know if it is correct

    tickmarkStepSize:( gauge_act_1.maximumValue - gauge_act_1.minimumValue)*0.1
    


  • @halima

    I believe there is no right or wrong formula it depends on what you want to display on your gauge.
    With your formula you will have always have 11 tick marks if this suits your need your formula is good no needs for another one.
    Your formula is taking the range of your gauge and divided it by 10 if you want an easy way to change the number of tick marks you can do this :

        property int  amountOfTick: 10 //Here you set the amount of tick you want
    
        Rectangle {
            width: 50
            height: 300
            anchors.centerIn: parent
            color: "transparent"
            property alias gauge: gauge_act_1
            Gauge {
                id: gauge_act_1
                minorTickmarkCount: 2
                font.pixelSize: 9
                anchors.centerIn: parent
                anchors.leftMargin: 2
                anchors.rightMargin: 2
                maximumValue : 481000
                minimumValue: 357000
                value : 420000
                tickmarkStepSize:( gauge_act_1.maximumValue - gauge_act_1.minimumValue)/(amountOfTick-1) //Here is the step calculation depending on the amount of tick you expect
                formatValue: function(value) {
                    return value.toFixed(1);
                }
    
                style: GaugeStyle {
    
                    valueBar: Rectangle {
                        color: "#FF003399"
                        implicitWidth: 15
                    }
                }
                objectName: "gauge_act_1"
            }
        }
    

    Hope this help you.



  • @halima Is your problem solved ? If yes you can change its status.



  • @DavidM29
    yes David thank you a lot!


Log in to reply
 

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