From 337eedb316e94217d6d8b4bb6dc664d26ef3a741 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Wed, 21 Mar 2012 16:23:33 +0200 Subject: [PATCH] Fixed QLineEdit to emit selectionChanged Was not emitted when removed by input method event. Change-Id: Ia2c0dcb09d42826188d4612f4c1705a41874a31d Reviewed-by: Andrew den Exter --- src/widgets/widgets/qwidgetlinecontrol.cpp | 2 ++ .../widgets/qlineedit/tst_qlineedit.cpp | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 7d97f6d295..ca30c7eef8 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -552,6 +552,8 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) } selectionChange = true; } else { + if (m_selstart != m_selend) + selectionChange = true; m_selstart = m_selend = 0; } cursorPositionChanged = true; diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 81dc940c00..f67f7ce1e8 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3846,13 +3846,26 @@ void tst_QLineEdit::inputMethodSelection() QCOMPARE(selectionSpy.count(), 1); QCOMPARE(testWidget->selectionStart(), 0); - QList attributes; - attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 12, 5, QVariant()); - QInputMethodEvent event("", attributes); - QApplication::sendEvent(testWidget, &event); + // selection gained + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 12, 5, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } QCOMPARE(selectionSpy.count(), 2); QCOMPARE(testWidget->selectionStart(), 12); + + // selection removed + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } + + QCOMPARE(selectionSpy.count(), 3); } void tst_QLineEdit::inputMethodTentativeCommit()