Hi,

I have a specific need: I'm drawing text in some custom box items in a QGraphicsView. The text is created from many string and I want to have individual control over those strings. e.g.: Change the color of a string that composes the whole string:

Angle: 123° - xxx <- I want to set the value in red for example

So at first, i've created a function that glues the strings together and I'm able to manage them. But today, I've found about QPainter::drawText() and it's ability to wrap the text using a bounding rect. So all my custom code can be reproduced by a couple of lines using drawText().

The problem I get is that drawText() does not support text formatting like HTML. So I've found out about QTextDocument::drawContents which supports HTML and pretty much all the same alignment options, but now the text is managed as a text document so I don't have any control over the vertical alignment of the text with the document's page. I want the vertical alignment to be related to the whole bounding rect instead of a single text line.

So my question: Is there a way to draw some text at any position within a bounding rect and having Qt automatically manage the alignment and word wrap, but at the same time being able to put some text formatting?

Thanks!