Draw QWidget under Text in QTextDocument
Solved
General and Desktop
-
I want to print a Text with a given QWidget under the Text, but everytime i open my PrintPreview the QWidget is painted over the Text. The QWidget always starts to paint at the Top Left Corner of the QTextDocument. How can i solve this? I need to know the Size of the actually Text and start painting it under this Position. This is my Code at the Moment. Im a little bit confused.
void Printer::printDiaryEvent(QPrinter *printer) { QTextDocument doc; QString html; html.append("<h2>" + mDate + "</h2><br><br>"); html.append(mDiaryText); doc.setHtml(html); doc.documentLayout()->setPaintDevice(printer); doc.setPageSize(printer->pageRect().size()); QPainter painter(printer); mRating->render(&painter); doc.drawContents(&painter, QRectF(doc.size().height(), 0, mRating->width(), mRating->height())); doc.print(printer); }
-
void Printer::printDiaryEvent(QPrinter *printer) { QTextDocument doc; QString html; html.append("<h2>" + mDate + "</h2><br><br>"); html.append(mDiaryText); QTextCursor cursor(&doc); cursor.insertHtml(html); // cursor.insertBlock(); // you might need this to have a separation between image and text, not sure cursor.insertImage(mRating.grab().toImage()); doc.documentLayout()->setPaintDevice(printer); doc.setPageSize(printer->pageRect().size()); doc.print(printer); }