Results 1 to 3 of 3

Thread: Issue of overlapping segments on a QwtPlotCurve with a thick transparent QPen

  1. #1

    Question Issue of overlapping segments on a QwtPlotCurve with a thick transparent QPen

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issue of overlapping segments on a QwtPlotCurve with a thick transparent QPen

    Using a pen with Qt::FlatCap and/or QwtPainter::setPolylineSplitting( false );

    HTH,
    Uwe

  3. #3

    Default Re: Issue of overlapping segments on a QwtPlotCurve with a thick transparent QPen

    Excellent! Thank you very much Uwe, cheers.

    Bob

Similar Threads

  1. Qt Designer Transparent Image Background Color Issue
    By CrispyBoardgames in forum Newbie
    Replies: 2
    Last Post: 19th July 2021, 20:41
  2. Container for TCP segments
    By morfis in forum Newbie
    Replies: 6
    Last Post: 31st May 2012, 18:31
  3. Qt Webkit 2.1 - SVG Issue - Object overlapping
    By Tushar in forum Qt Programming
    Replies: 0
    Last Post: 29th December 2010, 08:32
  4. Replies: 1
    Last Post: 6th May 2009, 15:29
  5. leaveEvent on transparent area issue
    By nooky59 in forum Qt Programming
    Replies: 10
    Last Post: 8th January 2008, 13:22

Tags for this Thread

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.