AFAIK the QTextCursor solution is the simplest.