From 1d0f808c7dc708f5ec8093f09f332615b94f4318 Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Wed, 13 Feb 2019 15:28:11 +0100 Subject: TextEdit: Fix persistentSelection for readonly controls TextEdit items with readOnly:true do not clear the selection on losing focus which is expected with persistentSelection:false. The reason is that a readonly TextEdit does never show a blinking cursor and thus the selection clearing within setCursorVisible never happens. This change adapts the implementation from TextInput. Fixes: QTBUG-50587 Change-Id: Ie66baaa0ccbc006359473862d8e9dbecd46a59f6 Reviewed-by: Shawn Rutledge Reviewed-by: Mitch Curtis --- .../quick/qquicktextedit/tst_qquicktextedit.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp') diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index f32da44daa..ce2a8eb257 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -1262,6 +1262,34 @@ void tst_qquicktextedit::persistentSelection() edit->setFocus(true); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + // QTBUG-50587 (persistentSelection with readOnly) + edit->setReadOnly(true); + + edit->setPersistentSelection(false); + QCOMPARE(edit->persistentSelection(), false); + QCOMPARE(spy.count(), 2); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setPersistentSelection(true); + QCOMPARE(edit->persistentSelection(), true); + QCOMPARE(spy.count(), 3); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); } void tst_qquicktextedit::selectionOnFocusOut() -- cgit v1.2.3