From 9f48f1ebc21f783cd8bb7daab942d70aebf085bc Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Thu, 15 Jun 2017 15:07:35 +0200 Subject: QLineEdit: Fix End key for input masks Consider this simple example: QLineEdit edit; edit.setInputMask( "9-9-9-9-9-9" ); edit.show(); Without any input, m_text will contain: " - - - - - ". text() removes the input mask's mask characters from that and returns " ". A string with 6 spaces. Thus currently the End key jumps to position 6, which is in the middle of the string. Using m_text the End key jumps to the actual end. [ChangeLog][QtWidgets][QLineEdit] Fixed End key in combination with certain input masks. Task-number: QTBUG-16187 Task-number: QTBUG-20414 Change-Id: Ibb30a1dfa2f78103611b5afc9971dc43e8bdcc4a Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qwidgetlinecontrol_p.h | 2 +- tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index 8ebed25084..a8fffd23dc 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -217,7 +217,7 @@ public: void cursorWordBackward(bool mark) { moveCursor(m_textLayout.previousCursorPosition(m_cursor, QTextLayout::SkipWords), mark); } void home(bool mark) { moveCursor(0, mark); } - void end(bool mark) { moveCursor(text().length(), mark); } + void end(bool mark) { moveCursor(m_text.length(), mark); } int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const; QRect rectForPos(int pos) const; diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 0cfbc651ad..d37fb5c173 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -760,6 +760,14 @@ void tst_QLineEdit::keypress_inputMask_data() keys.addKeyClick(Qt::Key_Delete); QTest::newRow("deleting all") << QString("000.000;_") << keys << QString(".") << QString("___.___"); } + { + QTestEventList keys; + // inserting at end + addKeySequenceStandardKey(keys, QKeySequence::MoveToEndOfLine); + keys.addKeyClick(Qt::Key_Left); + keys.addKeyClick(Qt::Key_0); + QTest::newRow("insert at end") << QString("9-9-9") << keys << QString("--0") << QString(" - -0"); + } { QTestEventList keys; // inserting '12.12' then two backspaces -- cgit v1.2.3