diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-04-08 19:58:03 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-04-10 07:14:09 +0000 |
commit | 04f4de502cd420da870b83e062a50833be63bde5 (patch) | |
tree | 432dabd955ab34edc35ab11af5c809565bc669b2 /src | |
parent | d3c628fbd7b7d7f2a83e3e77d9318bb930b8b3b6 (diff) |
QQuickLabel: fix background resizing
setBackground() must resize the item if component construction is
already complete.
Change-Id: I76cada5b37257473a9c0146ee1f6de8de6c10218
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 159599e97750ad1a9208a66303552aa8b4f2cdc7)
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquicklabel.cpp | 30 | ||||
-rw-r--r-- | src/quicktemplates2/qquicklabel_p_p.h | 2 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index c8b125ca..44baf1c3 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -95,6 +95,22 @@ QQuickLabelPrivate::~QQuickLabelPrivate() #endif } +void QQuickLabelPrivate::resizeBackground() +{ + Q_Q(QQuickLabel); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + /*! \internal @@ -232,6 +248,8 @@ void QQuickLabel::setBackground(QQuickItem *background) background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } if (!d->background.isExecuting()) emit backgroundChanged(); @@ -267,17 +285,7 @@ void QQuickLabel::geometryChanged(const QRectF &newGeometry, const QRectF &oldGe { Q_D(QQuickLabel); QQuickText::geometryChanged(newGeometry, oldGeometry); - if (d->background) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->background); - if (!p->widthValid) { - d->background->setWidth(newGeometry.width()); - p->widthValid = false; - } - if (!p->heightValid) { - d->background->setHeight(newGeometry.height()); - p->heightValid = false; - } - } + d->resizeBackground(); } QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicklabel_p_p.h b/src/quicktemplates2/qquicklabel_p_p.h index f612434b..2e60a96d 100644 --- a/src/quicktemplates2/qquicklabel_p_p.h +++ b/src/quicktemplates2/qquicklabel_p_p.h @@ -75,6 +75,8 @@ public: return static_cast<QQuickLabelPrivate *>(QObjectPrivate::get(item)); } + void resizeBackground(); + void resolveFont(); void inheritFont(const QFont &f); |