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.
How am I supposed to print a QGraphicsScene
that has text on it?
edit:
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);
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.
From the
QPrinter
docs it sounds like you have to specify font sizes in pixels to get text and graphics to match up. Note thatQFont
has asetPixelSize
method.