qt - QtTextEdit: text content not rendered to QPainter -
i have difficulties rendering context of qtextedit painter (which prints pdf). other widgets correctly printed, text of qtextwidget not.
the widgets fine in gui:
but text of qtextwidget not printed pdf:
the code quite simple. perhaps need add additional flags? text rendered same looks in gui, seperate rendering of text (using textfield->document()->drawcontents(&painter), not best solution)
qtextedit* textfield= ... // textedit correctly visible qprinter printer(qprinter::highresolution); ... qpainter painter( &printer ); textfield->render(&painter, qpoint(), qregion(), qwidget::drawchildren);
there nothing wrong code snippet. tried:
void mainwindow::on_pushbutton_clicked() { qprinter printer(qprinter::highresolution); printer.setoutputformat(qprinter::pdfformat); printer.setoutputfilename("output.pdf"); qpainter painter( &printer ); ui->textedit->render(&painter, qpoint(), qregion(), qwidget::drawchildren); }
and work's. i'm using qt 5.5.1.
you try (as alternative) textedit->print(printer);
or painter->drawtext(printer.pagerect(), ui->textedit->toplaintext());
Comments
Post a Comment