PDA

View Full Version : Setting textCursor position with line and column



titoaii
15th April 2010, 08:47
Hello everybody,

I'm trying to move the cursor of a QTextEdit to a position that is specified with line number and column. I've tried with movePosition() in the QTextCursor like this:


QTextEdit * editor;
//Moves the cursor to the beginning of the document
editor->textCursor().setPosition(0,QTextCursor::MoveAnchor );
//Now moves the cursor to the line "line" and in the column "index"
editor->textCursor().movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
editor->textCursor().movePosition(QTextCursor::NextCharact er, QTextCursor::MoveAnchor, index);


However, the only thing I get with this is the cursor in the same position as the beginning.
Does anybody know how to achieve this??

Thank you in advance!

Alberto

Lykurg
15th April 2010, 13:56
Use QTextCursor::NextBlock to go to the next line and you have to work with a copy of the cursor which has to be reset to to editor:
QTextCursor c = editor->textCursor();
c.movePosition(/*...*/);
editor->setCursor(c);