diff --git a/src/cpp/lib/core/FlexLayout/flexlayout.cpp b/src/cpp/lib/core/FlexLayout/flexlayout.cpp index 01bacda7e..f029968ba 100644 --- a/src/cpp/lib/core/FlexLayout/flexlayout.cpp +++ b/src/cpp/lib/core/FlexLayout/flexlayout.cpp @@ -10,7 +10,6 @@ FlexLayout::FlexLayout(QWidget* parentWidget, YGNodeRef parentNode) : QLayout(parentWidget) { this->node = parentNode; - this->setSizeConstraint(QLayout::SetFixedSize); } FlexLayout::~FlexLayout() { @@ -148,7 +147,14 @@ void FlexLayout::setGeometry(const QRect& rect) { if (!this->node) { return; } + if (this->sizeConstraint() != QLayout::SetFixedSize) { + YGNodeStyleSetHeight(this->node, rect.height()); + YGNodeStyleSetWidth(this->node, rect.width()); + } + calculateLayout(); + QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node); + QLayout::setGeometry(calculatedRect); uint count = YGNodeGetChildCount(this->node); @@ -159,7 +165,6 @@ void FlexLayout::setGeometry(const QRect& rect) { QLayoutItem* childItem = ctx->layoutItem(); childItem->setGeometry(childRect); } - QLayout::setGeometry(rect); } void FlexLayout::setFlexNode(YGNodeRef parentNode) { this->node = parentNode; } diff --git a/src/demo.ts b/src/demo.ts index 338d4d139..379c1e3f2 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -41,6 +41,7 @@ label.setInlineStyle(`border: 2px solid green;padding: 10;`); center.setLayout(new FlexLayout()); center.layout?.addWidget(label); +center.layout?.setProperty('sizeConstraint', 3); scrollArea.setWidget(center); win.setCentralWidget(scrollArea); win.show();