QWidget text editors to commit text on their own on losing focus
Change-Id: I3b907661e8a24a6dbdaabf607c5c528b1b471c98 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
b5c37d9e13
commit
dc2a1aff9b
@ -10214,10 +10214,8 @@ bool QGraphicsTextItem::sceneEvent(QEvent *event)
|
||||
case QEvent::KeyRelease:
|
||||
// Reset the focus widget's input context, regardless
|
||||
// of how this item gained or lost focus.
|
||||
if (event->type() == QEvent::FocusIn) {
|
||||
if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {
|
||||
qApp->inputPanel()->reset();
|
||||
} else if (event->type() == QEvent::FocusOut) {
|
||||
qApp->inputPanel()->commit();
|
||||
} else {
|
||||
qApp->inputPanel()->update(Qt::ImQueryInput);
|
||||
}
|
||||
|
@ -822,7 +822,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
|
||||
// the views, but if we are changing focus, we have to
|
||||
// do it ourselves.
|
||||
if (qApp)
|
||||
qApp->inputPanel()->commit();
|
||||
qApp->inputPanel()->reset();
|
||||
}
|
||||
|
||||
focusItem = 0;
|
||||
|
@ -1989,7 +1989,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
|
||||
// or it is not created fully yet.
|
||||
|| (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled)
|
||||
|| !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
|
||||
qApp->inputPanel()->commit();
|
||||
qApp->inputPanel()->reset();
|
||||
qApp->inputPanel()->setInputItem(0);
|
||||
}
|
||||
#endif //QT_NO_IM
|
||||
|
@ -3132,7 +3132,7 @@ void QWidgetPrivate::setEnabled_helper(bool enable)
|
||||
if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
|
||||
qApp->inputPanel()->setInputItem(focusWidget);
|
||||
} else {
|
||||
qApp->inputPanel()->commit();
|
||||
qApp->inputPanel()->reset();
|
||||
qApp->inputPanel()->setInputItem(0);
|
||||
}
|
||||
}
|
||||
@ -10191,7 +10191,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
|
||||
QWidget *focusWidget = d->effectiveFocusWidget();
|
||||
if (on && !internalWinId() && hasFocus()
|
||||
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
|
||||
qApp->inputPanel()->commit();
|
||||
qApp->inputPanel()->reset();
|
||||
qApp->inputPanel()->setInputItem(0);
|
||||
}
|
||||
if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()
|
||||
@ -10244,7 +10244,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
|
||||
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
|
||||
qApp->inputPanel()->setInputItem(focusWidget);
|
||||
} else if (!on && qApp->inputPanel()->inputItem() == focusWidget) {
|
||||
qApp->inputPanel()->commit();
|
||||
qApp->inputPanel()->reset();
|
||||
qApp->inputPanel()->setInputItem(0);
|
||||
}
|
||||
#endif //QT_NO_IM
|
||||
|
@ -1751,6 +1751,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e)
|
||||
reason != Qt::PopupFocusReason)
|
||||
deselect();
|
||||
|
||||
d->control->commitPreedit();
|
||||
d->setCursorVisible(false);
|
||||
d->control->setCursorBlinkPeriod(0);
|
||||
#ifdef QT_KEYPAD_NAVIGATION
|
||||
|
@ -2046,6 +2046,7 @@ void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e)
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
commitPreedit();
|
||||
setBlinkingCursorEnabled(false);
|
||||
|
||||
if (cursorIsFocusIndicator
|
||||
|
@ -3854,6 +3854,13 @@ void tst_QLineEdit::inputMethodTentativeCommit()
|
||||
QCOMPARE(testWidget->text(), QString(""));
|
||||
testWidget->setValidator(0);
|
||||
delete validator;
|
||||
|
||||
// text remains when focus is removed
|
||||
testWidget->setText(""); // ensure input state is reset
|
||||
QApplication::sendEvent(testWidget, &event);
|
||||
QFocusEvent lostFocus(QEvent::FocusOut);
|
||||
QApplication::sendEvent(testWidget, &lostFocus);
|
||||
QCOMPARE(testWidget->text(), QString("test"));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user