Search code examples
qtqpainter

Rich text to image in QT


In my application , have a QTextEdit dialog that accepts Rich Text Input. I need to convert this input in to an image for some purpose .

If it was Plain text i could use DrawText associated with the QPainter class . But Rich text cannot be dealt the same way as we don't know the formatting done.

Any suggestions on how to convert ?


Solution

  • You may use QTextEdit::document + QTextDocument::drawContents. You don't need any hacks with rendering widgets, as proposed by other authors, because there may be some problems with anti-aliasing settings.