aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicklabel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquicklabel.cpp')
-rw-r--r--src/quicktemplates2/qquicklabel.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp
index 724fd086..d27393ae 100644
--- a/src/quicktemplates2/qquicklabel.cpp
+++ b/src/quicktemplates2/qquicklabel.cpp
@@ -38,6 +38,7 @@
#include "qquicklabel_p_p.h"
#include "qquickcontrol_p.h"
#include "qquickcontrol_p_p.h"
+#include "qquickdeferredexecute_p_p.h"
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquicktext_p.h>
@@ -202,6 +203,20 @@ QAccessible::Role QQuickLabelPrivate::accessibleRole() const
}
#endif
+static inline QString backgroundName() { return QStringLiteral("background"); }
+
+void QQuickLabelPrivate::executeBackground(bool complete)
+{
+ Q_Q(QQuickLabel);
+ if (background.wasExecuted())
+ return;
+
+ if (!background)
+ quickBeginDeferred(q, backgroundName(), background);
+ if (complete)
+ quickCompleteDeferred(q, backgroundName(), background);
+}
+
QQuickLabel::QQuickLabel(QQuickItem *parent)
: QQuickText(*(new QQuickLabelPrivate), parent)
{
@@ -237,7 +252,9 @@ void QQuickLabel::setFont(const QFont &font)
*/
QQuickItem *QQuickLabel::background() const
{
- Q_D(const QQuickLabel);
+ QQuickLabelPrivate *d = const_cast<QQuickLabelPrivate *>(d_func());
+ if (!d->background)
+ d->executeBackground();
return d->background;
}
@@ -247,14 +264,15 @@ void QQuickLabel::setBackground(QQuickItem *background)
if (d->background == background)
return;
- QQuickControlPrivate::destroyDelegate(d->background, this);
+ delete d->background;
d->background = background;
if (background) {
background->setParentItem(this);
if (qFuzzyIsNull(background->z()))
background->setZ(-1);
}
- emit backgroundChanged();
+ if (!d->background.isExecuting())
+ emit backgroundChanged();
}
/*!
@@ -300,6 +318,7 @@ void QQuickLabel::classBegin()
void QQuickLabel::componentComplete()
{
Q_D(QQuickLabel);
+ d->executeBackground(true);
QQuickText::componentComplete();
#if QT_CONFIG(accessibility)
if (QAccessible::isActive())