aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2023-04-11 13:44:33 +0800
committerMitch Curtis <mitch.curtis@qt.io>2023-04-19 10:57:41 +0800
commit2d99c70f982da92c70c022551cf456877141a5c8 (patch)
treebdb87010d3bb78f3cfb3d14907fd0cc8a88762eb /src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp
parentfd489252a7c904c70afa299528b164d17e628dd8 (diff)
Material: fix TextArea decorations when in a Flickable
This patch fixes the following issues when the Material TextArea is attached to a Flickable: - Floating placeholder text scrolls with the Flickable. - When text is cleared without the control having focus: - Floating placeholder text is positioned incorrectly. - The floating text background outline gap is still open. - The background outline color is incorrect when the control has focus (used primaryTextColor instead of accentColor). Pick-to: 6.5 Task-number: QTBUG-112650 Change-Id: Icfa3517e4abcb1209ea2291dabdec225011f19ef Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp')
-rw-r--r--src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp b/src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp
index 2751efaa66..e987ce5610 100644
--- a/src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp
+++ b/src/quickcontrols/material/impl/qquickmaterialtextcontainer.cpp
@@ -272,7 +272,8 @@ void QQuickMaterialTextContainer::paint(QPainter *painter)
painter->setRenderHint(QPainter::Antialiasing, true);
- const bool focused = parentItem() && parentItem()->hasActiveFocus();
+ auto control = textControl();
+ const bool focused = control && control->hasActiveFocus();
// We still want to draw the stroke when it's filled, otherwise it will be a pixel
// (the pen width) too narrow on either side.
QPen pen;
@@ -317,6 +318,16 @@ bool QQuickMaterialTextContainer::shouldAnimateOutline() const
return !m_controlHasText && m_placeholderHasText;
}
+/*!
+ \internal
+
+ \sa QQuickPlaceholderText::textControl().
+*/
+QQuickItem *QQuickMaterialTextContainer::textControl() const
+{
+ return qobject_cast<QQuickItem *>(parent());
+}
+
void QQuickMaterialTextContainer::controlGotActiveFocus()
{
const bool shouldAnimate = m_filled ? !m_controlHasText : shouldAnimateOutline();
@@ -367,9 +378,16 @@ void QQuickMaterialTextContainer::startFocusAnimation()
void QQuickMaterialTextContainer::maybeSetFocusAnimationProgress()
{
- // Show the interrupted outline when there is text.
- if (!m_filled && m_controlHasText && m_placeholderHasText)
+ if (m_filled)
+ return;
+
+ if (m_controlHasText && m_placeholderHasText) {
+ // Show the interrupted outline when there is text.
setFocusAnimationProgress(1);
+ } else if (!m_controlHasText && !m_controlHasActiveFocus) {
+ // If the text was cleared while it didn't have focus, don't animate, just close the gap.
+ setFocusAnimationProgress(0);
+ }
}
void QQuickMaterialTextContainer::componentComplete()