如何在MFC应用程序中打印QGraphicsTextItem
我在 MFC 应用程序中使用 QGraphicsTextItem 进行文本编辑,然后将结果转换为位图以显示在视图(屏幕)中。但打印时出现问题。例如,如果我打印到 PDF 文件,则文本不可缩放,因为它是位图并且文件大小也很大。
如何在MFC打印框架中打印QGraphicsTextItem?理想的解决方案是我们可以将 QPrinter 连接到 MFC 打印框架中,或者我可以使用 Win32 DC 初始化 QPrinter。 MFC打印框架已经为我准备了打印机和DC,所以我不需要QPrintDialog再次执行该任务。 代码可能是这样的:
QPrinter printer;
printer.paintEngine()->setDC(myHDC); //**Note: this line is imagined by me.
QPainter painter(&printer);
这可能吗?我必须重新实现我自己的 QPrinter 吗?浏览QPrinter的源代码,发现它非常复杂。我希望有一种简单的方法来实现我的目标。如果我必须实现自己的QPrinter,我需要注意什么?有人可以给我一些建议吗?
I have used QGraphicsTextItem in my MFC applications for text editing, then converted the results to a bitmap to show in the view (screen). But it has issues when printing. For example, if I print to a PDF file, the text is not scalable since it is a bitmap and the file size is also big.
How can I print the QGraphicsTextItem in the MFC printing framework? The ideal solution is that we can hook QPrinter into the MFC printing framework or I can initialize QPrinter with Win32 DC. MFC printing framework has prepared printer and DC for me, so I don't need QPrintDialog to do that task again. The code may something like this:
QPrinter printer;
printer.paintEngine()->setDC(myHDC); //**Note: this line is imagined by me.
QPainter painter(&printer);
Is that possible? Do I have to reimplement my own QPrinter? Scanning QPrinter's source code, I found it very complex. I hope there is an easy way to get my goal. If I have to implement my own QPrinter, what should I need to notice? Can anyone give me some advices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论