Restoring cursor position in QTextEdit
Hi people,
I am trying to save to current cursor position, which i want to restore later on. It seems that restoring does not update the actual cursor. Here is a code snippet:
Code:
// in constuctor
void CCodeWidgetText::saveCursor()
{
this->cursorPos = this->pTextCursor->position();
}
void CCodeWidgetText::restoreCursor()
{
pTextCursor
->setPosition
(this
->cursorPos,
QTextCursor::MoveAnchor);
//this->setTextCursor(*pTextCursor);
}
Before this I tried to save the whole QTextCursor object and later on restore it, but that didn't seem to work either. Can someone help me out?
Thanks in advance
Re: Restoring cursor position in QTextEdit
Code:
// pTextCursor = new QTextCursor(this->document()); // forget this
void CCodeWidgetText::saveCursor()
{
this->cursorPos = this->textCursor().position();
}
void CCodeWidgetText::restoreCursor()
{
cursor.
setPosition(this
->cursorPos,
QTextCursor::MoveAnchor);
this->setTextCursor(cursor);
}
Re: Restoring cursor position in QTextEdit