summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2010-12-14 01:22:50 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2010-12-14 01:46:45 (GMT)
commit2eee49127b80b5b56c605f76ccea004b03d89577 (patch)
tree196c58e22d3e21872c5656d9789a7d1330d581d6 /tests/auto/declarative
parent896cd4bd08181ad16ad9cee6d2aaa1844a4f06d3 (diff)
downloadQt-2eee49127b80b5b56c605f76ccea004b03d89577.zip
Qt-2eee49127b80b5b56c605f76ccea004b03d89577.tar.gz
Qt-2eee49127b80b5b56c605f76ccea004b03d89577.tar.bz2
Remove active selection when TextEdit loses focus
Task-number: QTBUG-15341 Reviewed-by: Yann Bodson
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index a7971cc..ed02451 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -110,6 +110,7 @@ private slots:
void mouseSelection_data();
void mouseSelection();
void inputMethodHints();
+ void clearSelectionOnFocusLost();
void cursorDelegate();
void delegateLoading_data();
@@ -748,6 +749,45 @@ void tst_qdeclarativetextedit::inputMethodHints()
QVERIFY(textEditObject->inputMethodHints() & Qt::ImhUppercaseOnly);
}
+// QTBUG-15341
+void tst_qdeclarativetextedit::clearSelectionOnFocusLost()
+{
+
+ // create a visible scene with two text edits
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ QDeclarativeTextEdit edit;
+ QDeclarativeTextEdit secondEdit;
+ edit.setText("Hello world!");
+ scene.addItem(&edit);
+ scene.addItem(&secondEdit);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
+
+ int index = 0;
+ while (index < Qt::NoFocusReason) {
+
+ // focus the first text edit and select text
+ edit.setFocus(true);
+ edit.selectAll();
+ QVERIFY(edit.hasActiveFocus() && !secondEdit.hasActiveFocus());
+ QCOMPARE(edit.selectedText().size(), 12);
+
+ // lose focus in the first text edit
+ qobject_cast<QGraphicsObject*>(&secondEdit)->setFocus(Qt::FocusReason(index));
+ QVERIFY(!edit.hasActiveFocus() && secondEdit.hasActiveFocus());
+
+ // depending on the focus reason, selection should now be cleared
+ bool clearSelection = (index != Qt::ActiveWindowFocusReason && index != Qt::PopupFocusReason);
+ QCOMPARE(edit.selectedText().isEmpty(), clearSelection);
+ index++;
+ }
+}
+
+
+
void tst_qdeclarativetextedit::cursorDelegate()
{
QDeclarativeView* view = createView(SRCDIR "/data/cursorTest.qml");