SHREERAKSHA BHAT
SHREERAKSHA BHAT

Reputation: 27

Bring the property of one Id into another Id in QT

I want the scale value of this property into other Qml. How to do that

center.qml

Item {
id:paneItem

Rectangle{
    id:rectItem

    width: parent.width*0.8
    height: parent.height*0.8   }
 }

left.qml

Item{
 
 Rectangle{
          id:zoomRect
          anchors.bottom: parent.bottom
          anchors.left: parent.left

    Image {
        id: zoomIn
        source: "qrc:/images/centerPanel/zoomIn.png"
        anchors.top: zoomOut.bottom

        width: parent.width
        height: parent.height/2

        MouseArea {
            anchors.fill: parent
            onClicked: {
                if( zoombar.scale < 3.5)
                   zoombar.scale += zoom_offset
            }
        }
      }
    }
    
        
   Center{
    id:zoombar
    scale:RectItem.scale    
   }

How to get the control of rectangle RectItem from Center into Left??

Upvotes: 0

Views: 75

Answers (1)

JarMan
JarMan

Reputation: 8277

You are trying to access a property from a child object of a component. You can do that by simply exposing the child property through a property in the parent (usually an alias property).

Center.qml

Item {
    id: paneItem
    property alias rectScale: rectItem.scale // Exposes just the scale prop

    Rectangle {
        id: rectItem  // IDs should start with lower-case, btw.

        width: parent.width*0.8
        height: parent.height*0.8
    }
}

Left.qml

    Image {
        id: zoomIn
        source: "qrc:/images/centerPanel/zoomIn.png"
        anchors.top: zoomOut.bottom

        width: parent.width
        height: parent.height/2

        MouseArea {
            anchors.fill: parent
            onClicked: {
                if( zoombar.rectScale < 3.5)
                   zoombar.rectScale += zoom_offset
            }
        }

    
        
   Center{
    id:zoombar
   }

Upvotes: 2

Related Questions