Terribly sorry, but it turned out to be my fault all along. The line responsible was: textDoc.setDocumentMargin(0); in the sizeHint() method.