Quote Originally Posted by giusepped View Post
I think both print functions of QwtPlot have bugs.
I tried saving the images without printing as suggested by cnbp173, and all works.
Same for the svg. Not using the printing function but using the save function of the QPaintDevice seems to work. The only bad thing is that we get also the background color of the widget.

I attach the code I checked.

Qt Code:
  1. void MyPlot::exportSVG()
  2. {
  3. QString fileName;
  4.  
  5.  
  6. fileName = QFileDialog::getSaveFileName(this, tr("Nome file da esportare"), QString(),"Graphic files ( *svg)");
  7.  
  8. if ( !fileName.isEmpty() )
  9. {
  10. QSvgGenerator generator;
  11. generator.setFileName(fileName);
  12. generator.setSize(QSize(1024, 800));
  13. int options = QwtPlotPrintFilter::PrintAll;
  14. options |= QwtPlotPrintFilter::PrintBackground;
  15. options |= QwtPlotPrintFilter::PrintFrameWithScales| QwtPlotPrintFilter::PrintMargin;
  16. filter.setOptions(options);
  17. QPixmap pixmap = QPixmap::grabWidget(this);
  18. QPainter painter(&generator);
  19. painter.drawPixmap(0,0,-1,-1,pixmap);
  20.  
  21.  
  22.  
  23. // print(&painter,QRect(0,0,800,600),filter);:confused:
  24.  
  25.  
  26. }
  27.  
  28.  
  29. }
  30. void MyPlot::exportPNG()
  31. { QString fileName;
  32.  
  33. fileName = QFileDialog::getSaveFileName(this, tr("Nome file da esportare"), QString(),"Graphic files (*.png )");
  34.  
  35. if ( !fileName.isEmpty() )
  36. {
  37. // int options = QwtPlotPrintFilter::PrintAll;
  38. // int options = ~QwtPlotPrintFilter::PrintBackground;
  39. int options = QwtPlotPrintFilter::PrintFrameWithScales;
  40. options |= QwtPlotPrintFilter::PrintBackground;
  41. filter.setOptions(options);
  42.  
  43. QPixmap pixmap= QPixmap::grabWidget(this);
  44.  
  45.  
  46. //print(pixmap,filter );:confused:
  47.  
  48. if ( pixmap.save(fileName, "png" ))
  49. qDebug()<<"ok";
  50. else
  51. qDebug()<<"Uhmm";
  52. }
  53. }
To copy to clipboard, switch view to plain text mode 



thanks for this post