diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 627b444014..155646f465 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1981,7 +1981,6 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) || (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled) || !focus_widget->testAttribute(Qt::WA_WState_Created))))) { qApp->inputPanel()->reset(); - qApp->inputPanel()->setInputItem(0); } #endif //QT_NO_IM @@ -2005,13 +2004,6 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) QApplication::sendEvent(that->style(), &out); } if(focus && QApplicationPrivate::focus_widget == focus) { -#ifndef QT_NO_IM - if (focus->testAttribute(Qt::WA_InputMethodEnabled) - && focus->testAttribute(Qt::WA_WState_Created) - && focus->isEnabled()) { - qApp->inputPanel()->setInputItem(focus); - } -#endif //QT_NO_IM QFocusEvent in(QEvent::FocusIn, reason); QPointer that = focus; QApplication::sendEvent(focus, &in); @@ -2019,6 +2011,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) QApplication::sendEvent(that->style(), &in); } emit qApp->focusChanged(prev, focus_widget); + emit qApp->focusObjectChanged(focus_widget); } } } diff --git a/src/widgets/kernel/qinputcontext.cpp b/src/widgets/kernel/qinputcontext.cpp index 7c16234cdd..5bc37568be 100644 --- a/src/widgets/kernel/qinputcontext.cpp +++ b/src/widgets/kernel/qinputcontext.cpp @@ -172,7 +172,13 @@ QInputContext::~QInputContext() */ QWidget *QInputContext::focusWidget() const { - return qobject_cast(qApp->inputPanel()->inputItem()); + bool enabled = false; + if (qApp->focusWidget()) { + QInputMethodQueryEvent query(Qt::ImEnabled); + QGuiApplication::sendEvent(qApp->focusWidget(), &query); + enabled = query.value(Qt::ImEnabled).toBool(); + } + return enabled ? qobject_cast(qApp->focusWidget()) : 0; } @@ -186,7 +192,7 @@ QWidget *QInputContext::focusWidget() const */ void QInputContext::setFocusWidget(QWidget *widget) { - qApp->inputPanel()->setInputItem(widget); + // not honored } /*! diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 2dcda5eb4a..9a12efd6a8 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -355,7 +355,7 @@ void QWidgetPrivate::scrollChildren(int dx, int dy) void QWidgetPrivate::updateWidgetTransform() { Q_Q(QWidget); - if (q == qApp->inputPanel()->inputItem()) { + if (q == qGuiApp->focusObject()) { QTransform t; QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0)); t.translate(p.x(), p.y()); @@ -3125,10 +3125,10 @@ void QWidgetPrivate::setEnabled_helper(bool enable) if (enable) { if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) - qApp->inputPanel()->setInputItem(focusWidget); + qApp->inputPanel()->update(Qt::ImEnabled); } else { qApp->inputPanel()->reset(); - qApp->inputPanel()->setInputItem(0); + qApp->inputPanel()->update(Qt::ImEnabled); } } #endif //QT_NO_IM @@ -10137,7 +10137,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) if (on && !internalWinId() && hasFocus() && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { qApp->inputPanel()->reset(); - qApp->inputPanel()->setInputItem(0); + qApp->inputPanel()->update(Qt::ImEnabled); } if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget() #ifdef Q_WS_MAC @@ -10151,7 +10151,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) d->createWinId(); if (isEnabled() && focusWidget->isEnabled() && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { - qApp->inputPanel()->setInputItem(focusWidget); + qApp->inputPanel()->update(Qt::ImEnabled); } #endif //QT_NO_IM break; @@ -10184,13 +10184,10 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) break; case Qt::WA_InputMethodEnabled: { #ifndef QT_NO_IM - QWidget *focusWidget = d->effectiveFocusWidget(); - if (on && hasFocus() && isEnabled() - && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { - qApp->inputPanel()->setInputItem(focusWidget); - } else if (!on && qApp->inputPanel()->inputItem() == focusWidget) { - qApp->inputPanel()->reset(); - qApp->inputPanel()->setInputItem(0); + if (qApp->focusObject() == this) { + if (!on) + qApp->inputPanel()->reset(); + qApp->inputPanel()->update(Qt::ImEnabled); } #endif //QT_NO_IM break; diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 4d0bd6621c..cd019f4536 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -8889,6 +8889,8 @@ void tst_QWidget::inputFocus_task257832() QLineEdit *widget = new QLineEdit; widget->setFocus(); widget->winId(); // make sure, widget has been created + widget->show(); + QTRY_VERIFY(widget->hasFocus()); QCOMPARE(qApp->inputPanel()->inputItem(), static_cast(widget)); widget->setReadOnly(true); QVERIFY(!qApp->inputPanel()->inputItem()); @@ -9028,16 +9030,10 @@ void tst_QWidget::focusProxyAndInputMethods() // otherwise input method queries go to the wrong widget QCOMPARE(qApp->inputPanel()->inputItem(), toplevel); - child->setAttribute(Qt::WA_InputMethodEnabled, false); + toplevel->setAttribute(Qt::WA_InputMethodEnabled, false); QVERIFY(!qApp->inputPanel()->inputItem()); - child->setAttribute(Qt::WA_InputMethodEnabled, true); - QCOMPARE(qApp->inputPanel()->inputItem(), toplevel); - - child->setEnabled(false); - QVERIFY(!qApp->inputPanel()->inputItem()); - - child->setEnabled(true); + toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); QCOMPARE(qApp->inputPanel()->inputItem(), toplevel); delete toplevel;