Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qml use same rectangle component for multiple objects
Forum Updated to NodeBB v4.3 + New Features

qml use same rectangle component for multiple objects

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 202 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.
  • M Offline
    M Offline
    Mandeep.Chaudhary
    wrote on last edited by Mandeep.Chaudhary
    #1

    Hi,

    I am trying to reduce the size of qml file by calling same rectangle component and changing only the required fields and keep the rest same.

    The part shown below is working but want to reduce the size.

    Basically, I dont want to make moisture rectangle. I want to use temperature rectangle and modify say "x " value and inside connections modify only "path". Is that possible if yes than how ? thank you !!!

    Rectangle {
        id: landingScreen
        x: 0
        y: 0
        width: 800
        height: 350
        color: "#E4E4E4"
        visible: true
    
        property string path: ""
        property string val: ""
    
        Rectangle {
            id: temperature
            x: 8
            y: 11
            width: 351
            height: 329
            color: "#ffffff"
            radius: 10
            Text{
                id: textFieldtemp
                text :qsTr("")
                y:50
                font.family: "Helvetica"
                font.pointSize: 24
                anchors.horizontalCenter: parent.horizontalCenter
            }
    
            Connections
            {
                target: myModel
    
                onSensorValueChanged:{
    
                    path = "/root/temp"
                    val = value
                    if (addr === path)
                    {
                        textFieldtemp.text = "Temperature " + val + "*C"
                    }
                }
            }
        }
    
        Rectangle {
            id: moisture
            x: 369
            y: 13
            width: 209
            height: 157
            color: "#ffffff"
            radius: 10
    
            Text{
                id: textFieldmoist
                text :qsTr("")
                y:50
                font.family: "Helvetica"
                font.pointSize: 24
                anchors.horizontalCenter: parent.horizontalCenter
            }
    
            Connections
            {
                target: myModel
                onSensorValueChanged:{
    
                    path = "/root/moist"
                    val = value
                    if (addr === path)
                    {
                        textFieldmoist.text = "Moisture " + val + "*C"
                    }
                }
            }
        }
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mandeep.Chaudhary
      wrote on last edited by
      #2

      The nearest i go was using component and loader. but problem is declaring path is again a problem.

      ```
      
      Component {
              id: redSquare
      
              Rectangle {
                  id: temperature
                  x: 8
                  y: 11
                  width: 351
                  height: 329
                  color: "#ffffff"
                  radius: 10
                  property string path: "/root/temp"
                  property string val: ""
      
                  Text{
                      id: textFieldtemp
                      text :qsTr("")
                      y:50
                      font.family: "Helvetica"
                      font.pointSize: 24
                      anchors.horizontalCenter: parent.horizontalCenter
                  }
      
                  Connections
                  {
                      target: myModel
      
                      onSensorValueChanged:{
      
                       //   path = "/root/temp"
                          val = value
                          if (addr === path)
                          {
                              textFieldtemp.text = "Temperature " + val + "*C"
                          }
                      }
                  }
              }
          }
      
          Loader { sourceComponent: redSquare }
      
       //   Loader { sourceComponent: redSquare ; x:369; path:"/root/moist"}
      
      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