Skip to content

Commit af14a41

Browse files
committed
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).
1 parent cb05e9a commit af14a41

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/widgets/marginwrapper.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ void MarginWrapperManager::componentComplete() {
2727
this->mWrapper,
2828
&QQuickItem::widthChanged,
2929
this,
30-
&MarginWrapperManager::onWrapperWidthChanged
30+
&MarginWrapperManager::updateChildX
3131
);
3232

3333
QObject::connect(
3434
this->mWrapper,
3535
&QQuickItem::heightChanged,
3636
this,
37-
&MarginWrapperManager::onWrapperHeightChanged
37+
&MarginWrapperManager::updateChildY
3838
);
3939
}
4040

@@ -112,13 +112,13 @@ qreal MarginWrapperManager::targetChildY() const {
112112
}
113113
}
114114

115-
void MarginWrapperManager::onWrapperWidthChanged() {
115+
void MarginWrapperManager::updateChildX() {
116116
if (!this->mChild || !this->mWrapper) return;
117117
this->mChild->setX(this->targetChildX());
118118
this->mChild->setWidth(this->targetChildWidth());
119119
}
120120

121-
void MarginWrapperManager::onWrapperHeightChanged() {
121+
void MarginWrapperManager::updateChildY() {
122122
if (!this->mChild || !this->mWrapper) return;
123123
this->mChild->setY(this->targetChildY());
124124
this->mChild->setHeight(this->targetChildHeight());
@@ -127,11 +127,19 @@ void MarginWrapperManager::onWrapperHeightChanged() {
127127
void MarginWrapperManager::onChildImplicitWidthChanged() {
128128
if (!this->mChild || !this->mWrapper) return;
129129
this->mWrapper->setImplicitWidth(this->mChild->implicitWidth() + this->mMargin * 2);
130+
131+
// If the implicit width change does not result in an actual width change,
132+
// this will not be called anywhere else.
133+
this->updateChildX();
130134
}
131135

132136
void MarginWrapperManager::onChildImplicitHeightChanged() {
133137
if (!this->mChild || !this->mWrapper) return;
134138
this->mWrapper->setImplicitHeight(this->mChild->implicitHeight() + this->mMargin * 2);
139+
140+
// If the implicit height change does not result in an actual height change,
141+
// this will not be called anywhere else.
142+
this->updateChildY();
135143
}
136144

137145
void MarginWrapperManager::updateGeometry() {

src/widgets/marginwrapper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class MarginWrapperManager: public WrapperManager {
5555

5656
private slots:
5757
void onChildChanged();
58-
void onWrapperWidthChanged();
59-
void onWrapperHeightChanged();
58+
void updateChildX();
59+
void updateChildY();
6060
void onChildImplicitWidthChanged();
6161
void onChildImplicitHeightChanged();
6262

0 commit comments

Comments
 (0)