From bf5011815d917e07ae7cf45e5768f1775f70e90d Mon Sep 17 00:00:00 2001 From: Zhang Hao Date: Thu, 29 Oct 2020 15:24:26 +0800 Subject: [PATCH] InputMethod should call reset() function when proxywidget lost focus fix When the preview of input Chinese appears,the proxyWidget lose focus and does not call the reset method of inputMethod. Fixes: QTBUG-88016 Pick-to: 5.15 Change-Id: I82a66207b0d2046d768430ac3e93df86c1ed3681 Reviewed-by: Volker Hilsheimer --- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index c79c1e24c1..fcd675aa76 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -1391,6 +1391,11 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event) break; } + // QTBUG-88016 + if (d->widget && d->widget->focusWidget() + && d->widget->focusWidget()->testAttribute(Qt::WA_InputMethodEnabled)) + QApplication::inputMethod()->reset(); + d->proxyIsGivingFocus = false; } @@ -1406,8 +1411,14 @@ void QGraphicsProxyWidget::focusOutEvent(QFocusEvent *event) if (d->widget) { // We need to explicitly remove subfocus from the embedded widget's // focus widget. - if (QWidget *focusWidget = d->widget->focusWidget()) + if (QWidget *focusWidget = d->widget->focusWidget()) { + // QTBUG-88016 proxyWidget set QTextEdit(QLineEdit etc.) when input preview text, + // inputMethod should be reset when proxyWidget lost focus + if (focusWidget && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) + QApplication::inputMethod()->reset(); + d->removeSubFocusHelper(focusWidget, event->reason()); + } } }