Hello,

I'm trying to draw a QwtPlotCurve with a thick transparent QPen that has some alpha transparency. The issue is that when the straight line segments of the plotted curve overlap, the colors are added (blended?), changing the color of the overlapping region. Here is a minimal example with a single curve, plotted with a red pen, with a thickness of 16, and an alpha of 128:

https://i.imgur.com/Qxv7XOu.jpg
Qxv7XOu.jpg

Qt Code:
  1. #include "qwt_plot.h"
  2. #include "qwt_plot_curve.h"
  3.  
  4. #include <QApplication>
  5.  
  6. int main( int argc, char* argv[] )
  7. {
  8. QApplication app( argc, argv );
  9.  
  10. QwtPlot plot;
  11.  
  12. QPolygonF points;
  13. for (float t = 0.0; t < 10.0; t+=0.1f)
  14. points << QPointF(t,std::sin(t));
  15.  
  16. QwtPlotCurve *curve = new QwtPlotCurve();
  17. QColor color(255,0,0,128);
  18. curve->setPen(color, 16);
  19. curve->setSamples(points);
  20. curve->attach(&plot);
  21.  
  22. plot.show();
  23.  
  24. return app.exec();
  25. }
To copy to clipboard, switch view to plain text mode 





My reason for plotting with a thick pen with alpha is try and achieve a "glowing" effect by plotting the same line on top of itself a few times with different widths and alpha values. I've done this in other languages/plotting APIs such as matplotlib and it looks great, and I was hoping to do the same effect with Qwt. Here is a minimal working example of the effect, and a screenshot:

Qt Code:
  1. #include "qwt_plot.h"
  2. #include "qwt_plot_curve.h"
  3.  
  4. #include <QApplication>
  5.  
  6. void addCurve(QwtPlot *plot, const QPolygonF &points, QColor color, qreal width, qreal alpha)
  7. {
  8. QwtPlotCurve *curve = new QwtPlotCurve();
  9. color.setAlphaF(alpha);
  10. curve->setPen(color,width);
  11. curve->setSamples(points);
  12. curve->setRenderHint(QwtPlotItem::RenderAntialiased);
  13. curve->attach(plot);
  14. }
  15.  
  16. int main( int argc, char* argv[] )
  17. {
  18. QApplication app( argc, argv );
  19.  
  20. QwtPlot plot;
  21. plot.setCanvasBackground(QBrush(QColor(64,64,64)));
  22.  
  23. QPolygonF points;
  24. for (float t = 0.0; t < 10.0; t+=0.1f)
  25. points << QPointF(t,std::sin(t));
  26.  
  27. addCurve(&plot, points, Qt::green, 16, 0.05);
  28. addCurve(&plot, points, Qt::green, 10, 0.1);
  29. addCurve(&plot, points, Qt::green, 6, 0.15);
  30. addCurve(&plot, points, Qt::white, 2, 0.25);
  31.  
  32. plot.show();
  33.  
  34. return app.exec();
  35. }
To copy to clipboard, switch view to plain text mode 

And the result looks like this:

https://i.imgur.com/P55cAdj.jpg
P55cAdj.jpg

If you have any suggestions on how to plot the thick transparent curves without the overlapping segments showing, or other ideas about achieving this effect that would be great! Thank you very much,

Kind regards,

Bob