Reputation: 13
I want to creat a image that contain the QTextEdit. And I write the following code to create the image.
QSize s = textEdit->frameSize();
QPixmap p(s);
textEdit->render(&p);
p.save("textContent.png", "PNG");
But it can not contain the invisible contents.(while the contents is too long in QTextEdit)
I wander if there is a way to create a image which contain all the content in QTextEidt. And how.
Thanks.
Upvotes: 1
Views: 1226
Reputation: 3493
i think, you can do it like via QTextDocument * QTextEdit::document ()
to receive QTextDocument *
of your QTextEdit, and then draw it to QImage via void QTextDocument::drawContents ( QPainter * p, const QRectF & rect = QRectF() )
It draws the content of the document with painter p, clipped to rect. If rect is a null rectangle (default) then the document is painted unclipped.
check man here - http://harmattan-dev.nokia.com/docs/library/html/qt4/qtextdocument.html#drawContents
Or - the other way - take all the text from TextEdit via toPlainHtml() or toPlainText()
- what's more suitable for your needs and draw it to QImage via QPainter's method QPainter::DrawText()
Upvotes: 1