如何打印具有文本和图形的 QGraphicsScene [英] how to print a QGraphicsScene that has text and graphics
问题描述
我有一个 QGraphicsScene
,上面有图形和文字.当我尝试打印时,图形很好,但是文本使用的是以磅为单位定义的字体大小,因此当我将它传递给 QPainter
scene->render()> 用 QPrinter
初始化,有非常大的文本.
I have a QGraphicsScene
that has graphics as well as text drawn on it. When I try to print, the graphics are fine, but the text is using a font size defined in points, so scene->render()
when I pass it a QPainter
initialized with a QPrinter
, has VERY large text.
我应该如何打印带有文本的 QGraphicsScene
?
How am I supposed to print a QGraphicsScene
that has text on it?
这是我当前的打印代码,其中 scene_
是我自定义的 QGraphicsScene
子类:
Here is my current printing code, where scene_
is my custom subclass of QGraphicsScene
:
QPrinter printer(QPrinter::HighResolution);
QPrintDialog dialog(&printer, this);
dialog.exec();
std::cout << printer.resolution() << std::endl;
QPainter painter(&printer);
scene_->render(&painter);
std:cout 行似乎没有任何区别.打印机仍然认为文本很大,因此对于每个文本项,只打印了第一个字母的一小部分.
The std:cout line doesn't appear to make any difference. The printer still thinks the text is huge, so for each text item only a tiny part of the first letter is printed.
推荐答案
来自 QPrinter
docs 听起来您必须以像素为单位指定字体大小才能使文本和图形匹配.请注意,QFont
有一个 setPixelSize
方法.
From the QPrinter
docs it sounds like you have to specify font sizes in pixels to get text and graphics to match up. Note that QFont
has a setPixelSize
method.
这篇关于如何打印具有文本和图形的 QGraphicsScene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!