QTextDocument,QPdfWriter-如何缩放输出 [英] QTextDocument, QPdfWriter - how to scale output
问题描述
我创建了一个带有表的QTextDocument
.现在,我尝试使用QPdfWriter
(Qt 5.2.1)将其呈现为PDF格式.这是我的方法:
I have createated a QTextDocument
with a table in it. Now I'm trying to render it into PDF format using QPdfWriter
(Qt 5.2.1). This is how I do it:
QPdfWriter pdfWriter(output);
QPainter painter(&pdfWriter);
doc->drawContents(&painter);
它可以工作,但是问题在于PDF中的表格非常小.我该怎么做才能扩大规模?我的意思是按比例放大整个文档,而不仅仅是此表,因为我计划向文档中添加更多内容.
It works, but the problem is that the table in PDF is really, really tiny. What can I do to scale it up? I mean to scale up the whole document, not just this table, because I plan to add more contents to the document.
推荐答案
答案是使用QPainter::scale()
,所以在我的情况下:
The answer is to use QPainter::scale()
, so in my case:
QPdfWriter pdfWriter(output);
QPainter painter(&pdfWriter);
painter.scale(20.0, 20.0);
doc->drawContents(&painter);
这会使画家将所有东西都涂成20倍大.
This causes painter to paint everything 20 times bigger.
我仍然不知道为什么QPdfWriter
将所有东西都绘制得如此之细,但是问题可以如上所述解决.
I still don't know why QPdfWriter
paints everything so tiny, but the problem can be solved as above.
这篇关于QTextDocument,QPdfWriter-如何缩放输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!