Hi,

I want to print something. That's not a big problem: I create a QPrinter and a QPainter to paint on the QPrinter. I can draw an image and some text. I also want to draw some lines. In the preview window (QPrintPreviewDialog), everything looks fine. But, when I print to PDF with an external PDF-Printer or to a real printer, the lines lose their color and appear in black. The Textcolor remains at it should be...

Qt Code:
  1. void MyClass::Print(bool preview)
  2. {
  3. QPrinter *printer = new QPrinter(QPrinter::HighResolution;
  4. printer->setPageMargins(20,20,20,20,QPrinter::DevicePixel);
  5. printer->setColorMode(QPrinter::Color);
  6. printer->setPageSize(QPrinter::A4);
  7. printer->setPrintRange(QPrinter::AllPages);
  8.  
  9. if(preview)
  10. {
  11. QPrintPreviewDialog ppd(printer);
  12. connect(&ppd, SIGNAL(paintRequested(QPrinter*)), this, SLOT(Print(QPrinter*)));
  13. ppd.exec();
  14. }
  15. else
  16. {
  17. QPrintDialog *printDialog = new QPrintDialog(printer, CMainFrame::GetMainFrame().GetMainWin());
  18. if (printDialog->exec())
  19. Print(printer);
  20. }
  21. delete printer;
  22. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void MyClass::Print(QPrinter* printer)
  2. {
  3. //this is just a demonstration. My "real" code makes more sense ;)
  4.  
  5. QPainter p(printer);
  6. QRectF border(QPoint(0,0), printer->pageRect().size() - QSize(1,1));
  7.  
  8. p.setPen(Qt::red);
  9. p.drawRect(border);
  10.  
  11. QDateTime time = QDateTime::currentDateTime();
  12. QString timestr = time.toString("dddd, MMMM d, yyyy hh:mm:ss");
  13. p.drawText(400, 400, timestr);
  14.  
  15. p.drawLine(QLine(1000, 2000, 1800, 3500));
  16. }
To copy to clipboard, switch view to plain text mode 

see the attached results. Preview: preview.png, Print:print.png

what can I do to print colored lines? I could draw everything onto a QPixmap first and
print this QPixmap. But I think this may be too much memory-consuming, especially when printing in HighResolution mode...

thanks!
Felix