[Interest] Black background with QPrinter

Konrad Rosenbaum konrad at silmor.de
Fri Mar 17 11:16:45 CET 2017


Hi,

On Fri, March 17, 2017 02:03, Joshua Grauman wrote:
> I am trying to print a QTextDocument to PDF using QPrinter like the
> following. It works great. But now I'm trying to print to a PDF with a
> black background and I can't figure out how. If I do painter.fillRect() it
> doesn't cover the margins (margins are white). I've tried changing the
> document() stylesheet with no success. Does anyone know what is the best
> way to have a different color background for a PDF? Thanks!

You have to set the full page mode of the printer:

http://doc.qt.io/qt-5/qprinter.html#setFullPage

...otherwise it respects margins, which e.g. under Windows means the
margins of the worst printer you've got set up.

I presume you are generating those PDFs for display, not for printing.
Otherwise you need to be aware that anything that has an explicit color
will use toner or ink (yes, there are printers that have white ink). And
if you print it anyways: the margins of your printer are a hardware
property - so they'll be visible no matter what you tell QPrinter.


   Konrad




More information about the Interest mailing list