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 ?
You can grab the content of your QTextEdit in the following way:
QTextEdit te("This is a rich text");
te.resize(100, 100);
QPixmap pix = QPixmap::grabWidget (&te, te.rect());
pix.save("test.png");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With