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. [SOLVED] Volume calculation from 3 spinBox values
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Volume calculation from 3 spinBox values

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

    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?

    oria66O 1 Reply Last reply
    0
    • A ACaldas

      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?

      oria66O Offline
      oria66O Offline
      oria66
      wrote on last edited by
      #2

      @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;
          }
      }
      

      The truth is out there

      1 Reply Last reply
      1
      • A Offline
        A Offline
        ACaldas
        wrote on last edited by
        #3

        @oria66 Thank you so much! Works perfectly here.

        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