Bug 355779 - Add the property childrenRect to QMLItem
Summary: Add the property childrenRect to QMLItem
Status: REPORTED
Alias: None
Product: QmlWeb
Classification: Frameworks and Libraries
Component: QtQuick (show other bugs)
Version: unspecified
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Anton Kreuzkamp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-23 13:11 UTC by Igor A.
Modified: 2021-03-09 07:30 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor A. 2015-11-23 13:11:33 UTC
According to QML documentation Item must contain childrenRect object with properties (x,y,width,height). It's very useful and used frequently with ListView and Repeater. 

http://doc.qt.io/qt-5/qml-qtquick-item.html#childrenRect-prop

Reproducible: Always


Actual Results:  
No property  childrenRecct
Comment 1 Igor A. 2015-11-28 22:53:52 UTC
It works fine but I don't know how to update internally read only property yet. 

Here are my changes:

1) function computing the Rect 
function updateChildrenRect(component){
    
    var children = component !== undefined ? component.children : undefined
    if ( children == undefined || children.length == 0 )
        return;
    
    var maxWidth = 0;
    var maxHeight = 0;
    var minX = children.length>0 ? children[0].x : 0;
    var minY = children.length>0 ? children[0].y : 0;
    var h=0;
    var w=0;
    
    for(var i in children){
        var child = children[i];
        
        h = child.$isUsingImplicitHeight !== 0 ? child.implicitHeight : child.height;
        w = child.$isUsingImplicitWidth !== 0 ? child.implicitWidth : child.width;
        
        maxWidth = Math.max(maxWidth, child.x + w); 
        maxHeight = Math.max(maxHeight, child.y + h);
        minX = Math.min(minX, child.x);
        minY = Math.min(minX, child.y);
    }
    
    component.childrenRect.x = minX;
    component.childrenRect.y = minY;
    component.childrenRect.width = maxWidth;
    component.childrenRect.height = maxHeight; 
}

2) above to be called from  updateVGeometry and updateHGeometry

if (this.parent != undefined) updateChildrenRect(this.parent);

3) and a childrenRect property for QMLItem

    this.childrenRect = new QObject(this);
    createSimpleProperty("real", this.childrenRect, "x","rw");  //todo ro 
    createSimpleProperty("real", this.childrenRect, "y","rw");  // todo ro
    createSimpleProperty("real", this.childrenRect, "width","rw"); // todo ro
    createSimpleProperty("real", this.childrenRect, "height","rw"); // todo ro
Comment 2 Justin Zobel 2021-03-09 07:30:36 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.