Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Volume calculation from 3 spinBox values



  • Hi all,
    I want to calculate the volume of a cube by reading the value of three spinBox I have. How to do the multiplication operation and show up the result in a label? Is it possible to do it in a qml only?

    Could anyone help me?



  • @ACaldas Yes, this is a simple task in qml. This is a fast 5 min rapid prototype.

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Layouts 1.11
    
    ApplicationWindow {
        width: 640
        height: 480
        visible: true
        title: qsTr("Volume Multiplication")
    
       
        RowLayout {
            id: rowLayout
            anchors.fill: parent
    
            Label{
                Layout.fillWidth: true
                text: qsTr("Side A: ")
            }
    
            SpinBox {
                id: spinBoxSA
                onValueModified: result.text = calculateVolume(spinBoxSA.value, spinBoxSB.value, spinBoxH.value)
            }
    
            Label{
                text: qsTr("Side B: ")
                Layout.fillWidth: true
            }
    
            SpinBox {
                id: spinBoxSB
                onValueModified: result.text = calculateVolume(spinBoxSA.value, spinBoxSB.value, spinBoxH.value)
            }
    
            Label{
                text: qsTr("Height: ")
                Layout.fillWidth: true
            }
    
            SpinBox {
                id: spinBoxH
                onValueModified: result.text = calculateVolume(spinBoxSA.value, spinBoxSB.value, spinBoxH.value)
            }
    
            Label{
                text: qsTr("Rsult: ")
                Layout.fillWidth: true
            }
    
            Label{
                id: result
                Layout.fillWidth: true
            }
        }
    
        function calculateVolume(sideA, sideB, height)
        {
            return sideA*sideB*height;
        }
    }
    


  • @oria66 Thank you so much! Works perfectly here.


Log in to reply