From af14a416c1b12eaafc9e3af7985b2fccf5546860 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 29 Nov 2024 02:03:54 -0800 Subject: [PATCH] widgets/wrapper: update child geometry when implicit size changes The implicit size update from a child item of a MarginWrapper component triggers an implicit size update of the wrapper component, but this does not necessarily result in the actual size of the wrapper changing (e.g. when it is positioned by a layout). --- src/widgets/marginwrapper.cpp | 16 ++++++++++++---- src/widgets/marginwrapper.hpp | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/widgets/marginwrapper.cpp b/src/widgets/marginwrapper.cpp index 92de2935..5dc907ee 100644 --- a/src/widgets/marginwrapper.cpp +++ b/src/widgets/marginwrapper.cpp @@ -27,14 +27,14 @@ void MarginWrapperManager::componentComplete() { this->mWrapper, &QQuickItem::widthChanged, this, - &MarginWrapperManager::onWrapperWidthChanged + &MarginWrapperManager::updateChildX ); QObject::connect( this->mWrapper, &QQuickItem::heightChanged, this, - &MarginWrapperManager::onWrapperHeightChanged + &MarginWrapperManager::updateChildY ); } @@ -112,13 +112,13 @@ qreal MarginWrapperManager::targetChildY() const { } } -void MarginWrapperManager::onWrapperWidthChanged() { +void MarginWrapperManager::updateChildX() { if (!this->mChild || !this->mWrapper) return; this->mChild->setX(this->targetChildX()); this->mChild->setWidth(this->targetChildWidth()); } -void MarginWrapperManager::onWrapperHeightChanged() { +void MarginWrapperManager::updateChildY() { if (!this->mChild || !this->mWrapper) return; this->mChild->setY(this->targetChildY()); this->mChild->setHeight(this->targetChildHeight()); @@ -127,11 +127,19 @@ void MarginWrapperManager::onWrapperHeightChanged() { void MarginWrapperManager::onChildImplicitWidthChanged() { if (!this->mChild || !this->mWrapper) return; this->mWrapper->setImplicitWidth(this->mChild->implicitWidth() + this->mMargin * 2); + + // If the implicit width change does not result in an actual width change, + // this will not be called anywhere else. + this->updateChildX(); } void MarginWrapperManager::onChildImplicitHeightChanged() { if (!this->mChild || !this->mWrapper) return; this->mWrapper->setImplicitHeight(this->mChild->implicitHeight() + this->mMargin * 2); + + // If the implicit height change does not result in an actual height change, + // this will not be called anywhere else. + this->updateChildY(); } void MarginWrapperManager::updateGeometry() { diff --git a/src/widgets/marginwrapper.hpp b/src/widgets/marginwrapper.hpp index 7946951a..63b3eae2 100644 --- a/src/widgets/marginwrapper.hpp +++ b/src/widgets/marginwrapper.hpp @@ -55,8 +55,8 @@ signals: private slots: void onChildChanged(); - void onWrapperWidthChanged(); - void onWrapperHeightChanged(); + void updateChildX(); + void updateChildY(); void onChildImplicitWidthChanged(); void onChildImplicitHeightChanged();