Does anyone knows why this solution works?

Have this somewhere in your code..
// save cursor
int cur_position = win.textCursor().position();
One cannot use xxx.setPosition(cur_position) this on the object (QTextEdit) itself, but if one copy it to a local variable, change the local variable, and then write it it back, i can confirm this does work, but don't know why.

/** ---------------------------------------------------------------------------
* @brief display_gui::restore_cursor
* @param win Reference to a QTextEdit object
* @param cur_position The last known curser position
*/
void display_gui::restore_cursor (QTextEdit & win, int cur_position)
{
#ifdef DEBUG_CURSOR_RESTORE
fprintf (stderr,"..... b.NewPos %6d",win.textCursor().position());
#endif

//win.textCursor().setPosition(cur_position, QTextCursor::KeepAnchor); //QTextCursor::MoveAnchor);
//win.textCursor().movePosition(QTextCursor::End, QTextCursor::KeepAnchor); //QTextCursor::MoveAnchor);
// after many many hours .. this seem to be working !!!
// for some UNKNOWN REASON you cannot do this to the original, but you can copy it, change
// what you want , and write it back, then it works
QTextCursor my_cur = win.textCursor();

my_cur.setPosition(cur_position);
win.setTextCursor(my_cur);

#ifdef DEBUG_CURSOR_RESTORE
fprintf (stderr,"..... b.Restore %6d", cur_position);
#endif
}
What is also strange is that I tried to save the cursor in a QTextCursor variable, and restoring it, it does change the cursor position, but then one loose properties like underline and textcolor ??.

Thanks