QQuickText{Edit,Input}: Reset selection when becoming readOnly.

When read only, controls may not be edited or altered, and indeed, a read-only
control cannot acquire a selection (as it cannot be interacted with).
Leaving an existing selection breaks that implication, so clear it when becoming
read-only.

[ChangeLog][QtQuick][TextEdit/TextInput] If a control has a selection, it is now
cleared when becoming read-only.

Task-number: QTBUG-51115
Change-Id: Ife43b97ee3d6b780f09a938868c3ccb2f1b6e6e7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
Robin Burchell 2016-02-28 22:43:42 +01:00
parent 23712c5680
commit 83cb2069ea
6 changed files with 49 additions and 4 deletions

View File

@ -1534,8 +1534,7 @@ void QQuickTextEdit::setReadOnly(bool r)
if (!r)
flags = flags | Qt::TextEditable;
d->control->setTextInteractionFlags(flags);
if (!r)
d->control->moveCursor(QTextCursor::End);
d->control->moveCursor(QTextCursor::End);
#ifndef QT_NO_IM
updateInputMethod(Qt::ImEnabled);

View File

@ -679,8 +679,7 @@ void QQuickTextInput::setReadOnly(bool ro)
setFlag(QQuickItem::ItemAcceptsInputMethod, !ro);
#endif
d->m_readOnly = ro;
if (!ro)
d->setCursorPosition(d->end());
d->setCursorPosition(d->end());
#ifndef QT_NO_IM
updateInputMethod(Qt::ImEnabled);
#endif

View File

@ -0,0 +1,11 @@
import QtQuick 2.0
TextEdit {
Component.onCompleted: {
readOnly = false;
text= "bla bla";
selectAll();
readOnly = true;
}
}

View File

@ -201,6 +201,7 @@ private slots:
void doubleSelect_QTBUG_38704();
void padding();
void QTBUG_51115_readOnlyResetsSelection();
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
@ -5536,6 +5537,17 @@ void tst_qquicktextedit::padding()
delete root;
}
void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection()
{
QQuickView view;
view.setSource(testFileUrl("qtbug51115.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(view.rootObject());
QCOMPARE(obj->selectedText(), QString());
}
QTEST_MAIN(tst_qquicktextedit)
#include "tst_qquicktextedit.moc"

View File

@ -0,0 +1,11 @@
import QtQuick 2.0
TextInput {
Component.onCompleted: {
readOnly = false;
text= "bla bla";
selectAll();
readOnly = true;
}
}

View File

@ -221,6 +221,8 @@ private slots:
void ensureVisible();
void padding();
void QTBUG_51115_readOnlyResetsSelection();
private:
void simulateKey(QWindow *, int key);
@ -6697,6 +6699,17 @@ void tst_qquicktextinput::padding()
delete root;
}
void tst_qquicktextinput::QTBUG_51115_readOnlyResetsSelection()
{
QQuickView view;
view.setSource(testFileUrl("qtbug51115.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QQuickTextInput *obj = qobject_cast<QQuickTextInput*>(view.rootObject());
QCOMPARE(obj->selectedText(), QString());
}
QTEST_MAIN(tst_qquicktextinput)
#include "tst_qquicktextinput.moc"