PDA

View Full Version : Painting to QPrinter: Colour of cosmetic lines (0 width) fails



zooKeepr
7th July 2013, 15:27
When painting to a QPrinter object the colour of cosmetic lines is not shown. They are all printed in black, even with the printer colour mode set to colour (printer.setColorMode(QPrinter::Color)). However, when painting to a QGraphicsView object the colours appear correctly.

Oddly it seems that in order for the colour to be shown when painting to the printer object, the line width must be set >= 1. Setting the pen width to 1 is not desirable, as I apply a matrix transform to the painter and always want the line width to only be 1 pixel wide, independent of the transformation set on the painter. I have tried to undo the effect of the matrix transform with: pen.setWidth(1 / scaleFactor); // pen is a QPen object. However, this still does not result in colour printing.

In the interest of performance, I would like avoid drawing to a QPixmap first and then printing the pixmap. Any comments on potential solutions to this problem would be much appreciated.