aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquicklabel.cpp30
-rw-r--r--src/quicktemplates2/qquicklabel_p_p.h2
-rw-r--r--tests/auto/controls/data/tst_label.qml24
3 files changed, 45 insertions, 11 deletions
diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp
index 41b2d93a..8c94ee87 100644
--- a/src/quicktemplates2/qquicklabel.cpp
+++ b/src/quicktemplates2/qquicklabel.cpp
@@ -94,6 +94,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
@@ -279,6 +295,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();
@@ -359,17 +377,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 bcd1aca6..4d6c7de7 100644
--- a/src/quicktemplates2/qquicklabel_p_p.h
+++ b/src/quicktemplates2/qquicklabel_p_p.h
@@ -74,6 +74,8 @@ public:
return static_cast<QQuickLabelPrivate *>(QObjectPrivate::get(item));
}
+ void resizeBackground();
+
void resolveFont();
void inheritFont(const QFont &font);
void updateFont(const QFont &font);
diff --git a/tests/auto/controls/data/tst_label.qml b/tests/auto/controls/data/tst_label.qml
index 5618fe07..69d273a7 100644
--- a/tests/auto/controls/data/tst_label.qml
+++ b/tests/auto/controls/data/tst_label.qml
@@ -66,6 +66,18 @@ TestCase {
}
Component {
+ id: backgroundLabel
+ Label {
+ background: Rectangle { }
+ }
+ }
+
+ Component {
+ id: rectangle
+ Rectangle { }
+ }
+
+ Component {
id: signalSpy
SignalSpy { }
}
@@ -115,4 +127,16 @@ TestCase {
compare(child.font[data.tag], defaultValue)
compare(childSpy.count, 0)
}
+
+ function test_background() {
+ var control = createTemporaryObject(backgroundLabel, testCase, {text: "Label"})
+ verify(control)
+
+ compare(control.background.width, control.width)
+ compare(control.background.height, control.height)
+
+ control.background = rectangle.createObject(control)
+ compare(control.background.width, control.width)
+ compare(control.background.height, control.height)
+ }
}