0

How to move cursor one step backward in QLineEdit in Qt?

Any help is appreciated.

I tried

pLineEdit->cursorBackward(true,1);

but it does not work.

1
  • if cursorBackward() does not work, then what does cursorPosition() return?
    – Bart
    Jul 25, 2011 at 10:13

3 Answers 3

4

If you want to undo you just call undo function. If you want to go one character back you can use cursorBackward.

0

void QLineEdit::cursorBackward ( bool mark, int steps = 1 ); is exactly what you want, see docs

0

Have a look at the docs: http://doc.qt.io/qt-5/qlineedit.html#cursorPosition-prop

Use cursorPosition() to get the current position and then use setCursorPosition() to set it one step backward.

3
  • I tried this also int pos = pLineEdit->cursorPosition(); pLineEdit->setCursorPosition(pos -1); but it does not set the text one step backward, but when i debug it shows me correct cursor position.
    – Bokambo
    Jul 25, 2011 at 10:16
  • "set the text one step backward"... Did you mean "cursor" or do you really mean "text"?
    – Bart
    Jul 25, 2011 at 10:25
  • are you trying to implement backspace? or undo function?
    – Raiv
    Jul 25, 2011 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.