Hide cursor when text fields becomes read only
Clear the cursor node in TextEdit if field is read only. Otherwise the cursor stays visible indefinitely, if it were at the moment the flag was set. Task-number: QTBUG-44735 Change-Id: Ib39138260ad8a4d7e5ed2185b8a04c577ee1eff0 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
This commit is contained in:
parent
0f61aa5efe
commit
4e944555aa
|
@ -1436,6 +1436,11 @@ void QQuickTextEdit::setReadOnly(bool r)
|
|||
emit readOnlyChanged(r);
|
||||
if (!d->selectByKeyboardSet)
|
||||
emit selectByKeyboardChanged(!r);
|
||||
if (r) {
|
||||
setCursorVisible(false);
|
||||
} else if (hasActiveFocus()) {
|
||||
setCursorVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool QQuickTextEdit::isReadOnly() const
|
||||
|
@ -1937,9 +1942,9 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
|
|||
std::sort(d->textNodeMap.begin(), d->textNodeMap.end(), &comesBefore);
|
||||
}
|
||||
|
||||
if (d->cursorComponent == 0 && !isReadOnly()) {
|
||||
if (d->cursorComponent == 0) {
|
||||
QSGRectangleNode* cursor = 0;
|
||||
if (d->cursorVisible && d->control->cursorOn())
|
||||
if (!isReadOnly() && d->cursorVisible && d->control->cursorOn())
|
||||
cursor = d->sceneGraphContext()->createRectangleNode(d->control->cursorRect(), d->color);
|
||||
rootNode->resetCursorNode(cursor);
|
||||
}
|
||||
|
@ -2408,7 +2413,8 @@ void QQuickTextEditPrivate::handleFocusEvent(QFocusEvent *event)
|
|||
{
|
||||
Q_Q(QQuickTextEdit);
|
||||
bool focus = event->type() == QEvent::FocusIn;
|
||||
q->setCursorVisible(focus);
|
||||
if (!q->isReadOnly())
|
||||
q->setCursorVisible(focus);
|
||||
control->processEvent(event, QPointF(-xoff, -yoff));
|
||||
if (focus) {
|
||||
q->q_updateAlignment();
|
||||
|
|
|
@ -662,6 +662,12 @@ void QQuickTextInput::setReadOnly(bool ro)
|
|||
q_canPasteChanged();
|
||||
d->emitUndoRedoChanged();
|
||||
emit readOnlyChanged(ro);
|
||||
if (ro) {
|
||||
setCursorVisible(false);
|
||||
} else if (hasActiveFocus()) {
|
||||
setCursorVisible(true);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -2606,7 +2612,8 @@ void QQuickTextInputPrivate::handleFocusEvent(QFocusEvent *event)
|
|||
{
|
||||
Q_Q(QQuickTextInput);
|
||||
bool focus = event->gotFocus();
|
||||
q->setCursorVisible(focus);
|
||||
if (!m_readOnly)
|
||||
q->setCursorVisible(focus);
|
||||
if (focus) {
|
||||
q->q_updateAlignment();
|
||||
#ifndef QT_NO_IM
|
||||
|
|
|
@ -3192,6 +3192,7 @@ void tst_qquicktextinput::readOnly()
|
|||
QVERIFY(input != 0);
|
||||
QTRY_VERIFY(input->hasActiveFocus() == true);
|
||||
QVERIFY(input->isReadOnly() == true);
|
||||
QVERIFY(input->isCursorVisible() == false);
|
||||
QString initial = input->text();
|
||||
for (int k=Qt::Key_0; k<=Qt::Key_Z; k++)
|
||||
simulateKey(&window, k);
|
||||
|
@ -3204,6 +3205,7 @@ void tst_qquicktextinput::readOnly()
|
|||
input->setReadOnly(false);
|
||||
QCOMPARE(input->isReadOnly(), false);
|
||||
QCOMPARE(input->cursorPosition(), input->text().length());
|
||||
QVERIFY(input->isCursorVisible() == true);
|
||||
}
|
||||
|
||||
void tst_qquicktextinput::echoMode()
|
||||
|
|
Loading…
Reference in New Issue