[Interest] Black background with QPrinter

Joshua Grauman jnfo-c at grauman.com
Fri Mar 17 17:42:20 CET 2017


Thanks! That helps! Doing full page painting will work!

Yes, I'm generating these PDFs for viewing.

Thanks for the other info as well. I'm curious about your comment about 
printers with white ink. Presummably they could print on a black piece of 
paper. Would Qt support that? Or would the only way to support that be via 
the setFullPage option?

Josh

> 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