widgets: Don't report new focus object during clearFocus() unless needed
We do not unconditionally clear focus_child like the existing comment said. We only do it if the focus_child was the widget that is clearing focus. So in many cases we'll end up with the same focus object as before. We can not report that as a focusObjectChanged to the window, as that will potentially trigger a reset or cancel of the current input method for the (unchanged) focus object. Fixes: QTBUG-86976 Change-Id: I54367e46eda7a94d967f58960bd926c195dc09cc Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 7d5ba1c17ecbb620731ff7322fd278c3ce496dad) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
c5d904639d
commit
a778580339
@ -6715,6 +6715,9 @@ void QWidget::clearFocus()
|
|||||||
QApplication::sendEvent(this, &focusAboutToChange);
|
QApplication::sendEvent(this, &focusAboutToChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTLWExtra *extra = window()->d_func()->maybeTopData();
|
||||||
|
QObject *originalFocusObject = (extra && extra->window) ? extra->window->focusObject() : nullptr;
|
||||||
|
|
||||||
QWidget *w = this;
|
QWidget *w = this;
|
||||||
while (w) {
|
while (w) {
|
||||||
// Just like setFocus(), we update (clear) the focus_child of our parents
|
// Just like setFocus(), we update (clear) the focus_child of our parents
|
||||||
@ -6723,14 +6726,12 @@ void QWidget::clearFocus()
|
|||||||
w = w->parentWidget();
|
w = w->parentWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we've unconditionally cleared the focus_child of our parents, we need
|
// We've potentially cleared the focus_child of our parents, so we need
|
||||||
// to report this to the rest of Qt. Note that the focus_child is not the same
|
// to report this to the rest of Qt. Note that the focus_child is not the same
|
||||||
// thing as the application's focusWidget, which is why this piece of code is
|
// thing as the application's focusWidget, which is why this piece of code is
|
||||||
// not inside the hasFocus() block below.
|
// not inside a hasFocus() block.
|
||||||
if (QTLWExtra *extra = window()->d_func()->maybeTopData()) {
|
if (originalFocusObject && originalFocusObject != extra->window->focusObject())
|
||||||
if (extra->window)
|
emit extra->window->focusObjectChanged(extra->window->focusObject());
|
||||||
emit extra->window->focusObjectChanged(extra->window->focusObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
#if QT_CONFIG(graphicsview)
|
#if QT_CONFIG(graphicsview)
|
||||||
QWExtra *topData = d_func()->extra;
|
QWExtra *topData = d_func()->extra;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user