Qt - 在pdf上打印时QTextCursor insertImage低分辨率

时间:2014-07-25 12:25:43

标签: qt qtextdocument insert-image

我有一个QImage和一个QPainter,它描绘了这个图像。绘画后,我尝试使用QTextCursor的insertImage方法将此QImage插入QTextDocument:

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);

但是这样做之后我得到的是一张低分辨率的文字或像这张图片中的线宽下垂的像素:

!(http://imgim.com/4698inciz7774617.pngline image

我试过设置QTextDocument的布局的绘图设备,但由于空指针它给出了一个错误,这很可能是因为文档没有布局 我尝试设置画家的渲染提示,但它也不起作用。 我在文档中的图像之前插入了一些html,但它们在分辨率方面很好,平面线也没有问题。 当我在QTextEdit中显示此文档时,它看起来很好,但是当它在预览中的pdf文件中或出现问题时。 我的打印机在预览中的定义如下:

QPrinter printer(QPrinter::HighResolution);
QPrinter highprinter(QPrinter::ScreenResolution);
printer.setPaperSize(QPrinter::A4);

我打电话给QTextDocument的打印方法进行打印。 你有什么解决方案吗? 感谢

1 个答案:

答案 0 :(得分:0)

Saggy像素可以通过以下方式消除:QPainter :: setRenderHint(QPainter :: Antialiasing,true);但它似乎并没有消除字母中的凹凸像素。 完全消除下垂像素的其他方法是创建一个具有大像素大小(分辨率)和增加图像大小的文档。之后我们可以增加字体点大小和线宽,它可以防止像我在试验中看到的混叠。

//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);

然而,当图像的像素大小(分辨率)保持不变时,增加字体点大小并不能防止混叠

相关问题