diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-06-16 14:27:06 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-06-16 12:36:05 +0000 |
commit | cdec6d9db487399d960e8f0ae0b8b64bc70ae477 (patch) | |
tree | a3d20178d844f53f513447e064753f9299fcdeb0 | |
parent | 73f931a771e3576a9dd1daf6d13a6ef11eeee5a9 (diff) |
TextField: sync background resizing with Control
Change-Id: Iabf6e88fc929215af6e82fdd1493678b73a65dcd
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r-- | src/controls/qquicktextfield.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/controls/qquicktextfield.cpp b/src/controls/qquicktextfield.cpp index 0d85fa05..8c7cb310 100644 --- a/src/controls/qquicktextfield.cpp +++ b/src/controls/qquicktextfield.cpp @@ -49,11 +49,29 @@ class QQuickTextFieldPrivate public: QQuickTextFieldPrivate() : background(Q_NULLPTR), placeholder(Q_NULLPTR) { } + void resizeBackground(); + QQuickItem *background; QQuickText *placeholder; QQuickTextField *q_ptr; }; +void QQuickTextFieldPrivate::resizeBackground() +{ + Q_Q(QQuickTextField); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid && qFuzzyIsNull(background->x())) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid && qFuzzyIsNull(background->y())) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + QQuickTextField::QQuickTextField(QQuickItem *parent) : QQuickTextInput(parent), d_ptr(new QQuickTextFieldPrivate) { @@ -81,6 +99,8 @@ void QQuickTextField::setBackground(QQuickItem *background) background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); } emit backgroundChanged(); } @@ -108,17 +128,7 @@ void QQuickTextField::geometryChanged(const QRectF &newGeometry, const QRectF &o { Q_D(QQuickTextField); QQuickTextInput::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(); } QSGNode *QQuickTextField::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) |