I have a QImage and a QPainter that paints on this image. After painting I tried to insert this QImage to QTextDocument with QTextCursor's insertImage method :
QImage image(width ,height,QImage::Format_RGB32);
QPainter paint;
paint.begin(&image);
paint.drawText(25,25,someText);
paint.end();
QTextCursor cursor(doc);
cursor.movePosition(QTextCursor::End);
cursor.insertImage(image);
But after doing this what I got is a text with a low resolution or a line width saggy pixels like in this image :
!(http://imgim.com/4698inciz7774617.png)line image
I tried setting QTextDocument's layout's paint device but it gave an error because of null pointer, this is most probably because of the document does not have a layout I tried setting render hints of painter but it does not work too. I inserted some html before the image in the document but they are good in terms of resolution, also there are no problem in flat lines. When I show this document in a QTextEdit it seems fine, but when this is in a pdf file in a preview or something something goes wrong. My printer is defined like that in preview :
QPrinter printer(QPrinter::HighResolution);
QPrinter highprinter(QPrinter::ScreenResolution);
printer.setPaperSize(QPrinter::A4);
And I call QTextDocument's print method for printing. Do you have any solutions for this? thanks
Saggy pixels can be eliminated somehow with : QPainter::setRenderHint(QPainter::Antialiasing, true); however it seems it does not eliminate saggy pixels in letters very much. Other way of eliminating saggy pixels fully is creating a document with large pixel sizes (resolution) and increasing size of the image.After that we can increase font point size and line widths it prevents aliasing as I saw in my trials.
//increasing line width when drawing line
paint.setPen(QPen(Qt::gray,20, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
//increasing font's point size when using text
qFont2.setPointSize(100);
paint.setFont(qFont2);
However increasing font point size does not prevent aliasing when the image's pixel size (resolution) remains same