You can try taking a look at QTextDocument::drawCursor