pureqml/qmlcore

The size of the item is not calculated based on padding.

paiext opened this issue · 3 comments

Check the width and height values inside the style attribute of myRect in the following code.

  Rectangle {
    id: myRect;
    color: 'red';
    Paddings {
      all: 10;
    }
  }

style="background-color: rgb(255, 0, 0); padding: 10px;"

There is no width and height in the style attribute, which causes the central alignment to fail.

Another example:
The inner myRect should be centered.

    Rectangle {
      width: 30;
      height: 30;
      color: 'blue';
      Rectangle {
        id: myRect;
        color: 'red';
        anchors.centerIn: parent;
        Paddings {
          all: 10;
        }
      }     
    }

as a temporary workaround I'd suggest you using anchor.margins.

I'm not really sure we'll be able to fix it to support this example.
First of all, we don't modify user-accessible declarative attributes except a really few cases (anchors). So we can't adjust width property
Padding is modifying CSS padding, and you have to specify width yourself.

QML way to achieve similar functionality is available as anchors.margins, {left-top-right-bottom}Margin.

Item {
        anchors.fill: context;

    Rectangle {
      width: 30;
      height: 30;
      color: 'blue';
      Rectangle {
        id: myRect;
        width: 20; //<< here
        height: 20; //<< here
        color: 'red';
        anchors.centerIn: parent;
        Paddings {
          all: 10;
        }
      }
    }

}