0
votes

There's a kind of reusable element that have the property of Rectangle type:

property Item middleRegion: Rectangle {
   color: "grey";
   border.width: 1;
   height: line.height;
   parent: line
}

Then, if an user defines own middleRegion, onMiddleRegionChanged() is called:

onMiddleRegionChanged: {
    middleRegion.parent = line
    middleRegion.height = line.height
}

But, despite of the fact that line.height is changed, middleRegion.height isn't changed after it. Why does binding not work in this code?

The important thing that if user doesn't defined middleRegion, everything's going well.

1

1 Answers

0
votes

I've found the answer by myself.

According to the example from Qt documentation the problem is solved by using Qt.binding():

import QtQuick 2.0

Rectangle {
    width: 100
    height: width * 2

    focus: true
    Keys.onSpacePressed: {
        height = Qt.binding(function() { return width * 3 })
    }
}