// Create a QTextDocument QTextDocument doc; doc.setHtml("Hello, world!
"); // Create a QPainter object to draw on a QWidget QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); // Draw the contents of the QTextDocument onto the QWidget doc.drawContents(&painter, QRectF(0, 0, width(), height()));
// Create a QTextDocument QTextDocument doc; doc.setHtml("This example creates a QTextDocument with an HTML content, modifies the QTextOption of the QTextDocument to change the text justification to left, and finally draws the contents of the QTextDocument on a QImage. Package Library: Qt GUI LibrarySome text...
"); // Modify the QTextOption of the QTextDocument to change the text justification QTextOption textOption(Qt::AlignLeft | Qt::AlignVCenter); doc.setDefaultTextOption(textOption); // Draw the contents of the QTextDocument onto a QImage QImage image(400, 400, QImage::Format_ARGB32); image.fill(Qt::white); QPainter painter(&image); doc.drawContents(&painter);