Idea here is to let the user select as much text he wants in the text editor, then have a rectangle displayed around that selected area.

This rectangle has to take the shape of the selected text.

I found blockBoundingRect function which returns the bounding rectangle of the QTextBlock in the QTextBlock's own coordinates.

I am not sure if this would be of some help. What do I need to do to display the rectangle around the selected text?