如何在MFC应用程序中打印QGraphicsTextItem

发布于 2024-09-06 09:17:54 字数 574 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文