Widgets: Fix ImSurroundingText query for a QLineEdit with mask
QLineEdit with a mask does not return empty fields with the ImSurroundingText query. This is a problem for the input context that is not aware of the mask and relies on the fact that the cursor position never exceeds the boundaries of the surrounding text. This change fixes the issue by returning unmasked text with the ImSurroundingText query. [ChangeLog][QtWidgets][QLineEdit] Fixed behavior of the ImSurroundingText query. Previously, it returned a masked text whose length may be less than the cursor position. Now it returns unmasked text, so the text length is always greater than or equal to the cursor position. Task-number: QTBUG-60319 Change-Id: I1c8009164836a1baa2e3a45958bf1ea5fa9be38d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
parent
49cb039a5c
commit
8de79dbcec
@ -1773,7 +1773,7 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant arg
|
|||||||
return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
|
return QVariant(d->xToPos(pt.x(), QTextLine::CursorBetweenCharacters));
|
||||||
return QVariant(d->control->cursor()); }
|
return QVariant(d->control->cursor()); }
|
||||||
case Qt::ImSurroundingText:
|
case Qt::ImSurroundingText:
|
||||||
return QVariant(d->control->text());
|
return QVariant(d->control->surroundingText());
|
||||||
case Qt::ImCurrentSelection:
|
case Qt::ImCurrentSelection:
|
||||||
return QVariant(selectedText());
|
return QVariant(selectedText());
|
||||||
case Qt::ImMaximumTextLength:
|
case Qt::ImMaximumTextLength:
|
||||||
|
@ -250,6 +250,11 @@ public:
|
|||||||
|
|
||||||
QString displayText() const { return m_textLayout.text(); }
|
QString displayText() const { return m_textLayout.text(); }
|
||||||
|
|
||||||
|
QString surroundingText() const
|
||||||
|
{
|
||||||
|
return m_text.isNull() ? QString::fromLatin1("") : m_text;
|
||||||
|
}
|
||||||
|
|
||||||
void backspace();
|
void backspace();
|
||||||
void del();
|
void del();
|
||||||
void deselect() { internalDeselect(); finishChange(); }
|
void deselect() { internalDeselect(); finishChange(); }
|
||||||
|
@ -313,6 +313,8 @@ private slots:
|
|||||||
void shortcutOverrideOnReadonlyLineEdit();
|
void shortcutOverrideOnReadonlyLineEdit();
|
||||||
void QTBUG59957_clearButtonLeftmostAction();
|
void QTBUG59957_clearButtonLeftmostAction();
|
||||||
|
|
||||||
|
void QTBUG_60319_setInputMaskCheckImSurroundingText();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void editingFinished();
|
void editingFinished();
|
||||||
|
|
||||||
@ -4696,5 +4698,16 @@ bool tst_QLineEdit::unselectingWithLeftOrRightChangesCursorPosition()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QLineEdit::QTBUG_60319_setInputMaskCheckImSurroundingText()
|
||||||
|
{
|
||||||
|
QLineEdit *testWidget = ensureTestWidget();
|
||||||
|
QString mask("+000(000)-000-00-00");
|
||||||
|
testWidget->setInputMask(mask);
|
||||||
|
testWidget->setCursorPosition(mask.length());
|
||||||
|
QString surroundingText = testWidget->inputMethodQuery(Qt::ImSurroundingText).toString();
|
||||||
|
int cursorPosition = testWidget->inputMethodQuery(Qt::ImCursorPosition).toInt();
|
||||||
|
QCOMPARE(surroundingText.length(), cursorPosition);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QLineEdit)
|
QTEST_MAIN(tst_QLineEdit)
|
||||||
#include "tst_qlineedit.moc"
|
#include "tst_qlineedit.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user