raze
raze

Reputation: 692

Controlling keyboard position in QTextEdit

Is there any way to control the keyboard cursor in QTextEdit? For instance move the cursor one line up, or two positions back. I have looked at the QCursor class, but is this only for the mouse cursor? Thanks!

Upvotes: 0

Views: 569

Answers (2)

Oleh Prypin
Oleh Prypin

Reputation: 34116

QTextCursor::movePosition(MoveOperation operation, MoveMode mode=MoveAnchor, int n=1)

This method allows you to move the cursor in various ways, such as one word to the right or up one line.

You can use it like this:

QTextCursor c = textEdit->textCursor();
c.movePosition(QTextCursor::Up);
textEdit->setTextCursor(c);

If you need to select some text, not just move the cursor, specify the MoveMode as KeepAnchor.

Upvotes: 4

Related Questions