Results 1 to 3 of 3

Thread: How to get customized background printed?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question How to get customized background printed?

    Hello,

    I want to customize the background of a plot to make the output clearer. To do this I painted polygons onto the background canvas. The problem with this is, that using the print() method only outputs the originally chosen background color and ignores the polygons drawn onto the canvas.

    Grabbing the whole widget and printing its pixmap works like intended and returns the complete background, see graph3.png

    But when I try to save it as a pdf the polygons are left out, see graph.pdf

    Is there a way to get my polygons into the pdf output or do I have to live with jpg or png?

    Thanks for your help.

    Code used for plotting:

    Qt Code:
    1. void CGraph::printGraph()
    2. {
    3. this->replot();
    4. //filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::Options::PrintBackground);
    5.  
    6. int options = QwtPlotPrintFilter::PrintAll;
    7. //options |= QwtPlotPrintFilter::PrintBackground;
    8. //options |= QwtPlotPrintFilter::PrintFrameWithScales;
    9. filter.setOptions(options);
    10.  
    11. QPrinter printer;
    12. printer.setOrientation(QPrinter::Landscape);
    13. printer.setOutputFileName("graph.pdf");
    14. print(printer, filter);
    15.  
    16. QPixmap *image;
    17. QwtPlotCanvas *canvas;
    18. this->canvas();
    19. canvas = this->canvas();
    20. image = canvas->paintCache();
    21. image->save("graph2.png");
    22.  
    23. QPixmap pixmap= QPixmap::grabWidget(this);
    24. pixmap.save("graph3.png", "png" );
    25. }
    To copy to clipboard, switch view to plain text mode 

    Code for painting the background:

    Qt Code:
    1. void CGraph::drawCanvas(QPainter* painter)
    2. {
    3. QwtPolygon polygon(3);
    4.  
    5. painter->setPen(Qt::NoPen);
    6. painter->setBrush(Qt::red);
    7. painter->translate(0,canvas()->height());
    8.  
    9. polygon.setPoint(0,0,0);
    10. polygon.setPoint(1,canvas()->width(),0);
    11. polygon.setPoint(2,canvas()->width(),-canvas()->height());
    12.  
    13. painter->setBrush(QBrush(QColor(255,100,0)));
    14. qwtPainter.drawPolygon(painter,polygon);
    15.  
    16. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*6/7);
    17. qwtPainter.drawPolygon(painter,polygon);
    18.  
    19. painter->setBrush(QBrush(QColor(255,200,0)));
    20. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*5/7);
    21. qwtPainter.drawPolygon(painter,polygon);
    22.  
    23. painter->setBrush(Qt::yellow);
    24. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*4/7);
    25. qwtPainter.drawPolygon(painter,polygon);
    26.  
    27. painter->setBrush(QBrush(QColor(180,230,0)));
    28. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*3/7);
    29. qwtPainter.drawPolygon(painter,polygon);
    30.  
    31. painter->setBrush(Qt::darkGreen);
    32. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*2/7);
    33. qwtPainter.drawPolygon(painter,polygon);
    34.  
    35. painter->setBrush(Qt::green);
    36. polygon.setPoint(2,canvas()->width(),-(double)canvas()->height()*1/7);
    37. qwtPainter.drawPolygon(painter,polygon);
    38. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. QLCDNumber with transparent background?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 05:34
  2. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  3. Replies: 1
    Last Post: 5th April 2006, 16:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.