We do have a fix to the problem we were having with Qwt 6.1.3 (built with Qt 5.5.1) on Windows. This with the standard QwtLegend implementation. The fix is: commenting out the call to QPen::setCapStyle (Qt::FlatCap) in method QwtPlotCurve::legendIcon().

Uwe, and anyone else who knows about this. Is this fix (omitting call to setCapStyle) the right idea? Or am I missing something?

The two following screenshots show the discrepancy. Both have a line width of 2. Dotted, and Dashed:

Plot1-Prob-Dot2.png
Plot2-Prob-Dash2.png

http://cadswes2.colorado.edu/~philw/...-Prob-Dot2.png
http://cadswes2.colorado.edu/~philw/...Prob-Dash2.png

Here's a closer look at the problem. The "fixed" version matches what is shown on the plot:

LegendProb.jpg

http://cadswes2.colorado.edu/~philw/...LegendProb.png

The following show a fix -- effectively commenting out this line in QwtPlotCurve::legendIcon():
  • pn.setCapStyle( Qt::FlatCap );


Plot3-Fix-Dot2.png
Plot4-Fix-Dash2.png

http://cadswes2.colorado.edu/~philw/...3-Fix-Dot2.png
http://cadswes2.colorado.edu/~philw/...-Fix-Dash2.png

Instead of actually modifying QwtPlotCurve::legendIcon(), we lifted that implementation out of that class, and implemented a modified version in our QwtPlotCurve subclass.

Qt Code:
  1. // virtual from QwtPlotCurve
  2. QwtGraphic SlotCurve::legendIcon (int index, // (ignore, only one)
  3. const QSizeF& iconSize) const
  4. {
  5. // call base class method
  6. //-- QwtGraphic graphic = QwtPlotCurve::legendIcon (index, iconSize);
  7.  
  8. // Note [Phil, 3-2017, RW 7.1, Qwt 6.1.3, Qt 5.5.1, Gnats 5864]:
  9. // The following code is adapted from QwtPlotCurve::legendIcon().
  10. // See the fix for Gnats 5864, below ("Legend and plot line look
  11. // different if thickness is greater than one").
  12.  
  13. Q_UNUSED( index );
  14.  
  15. if ( iconSize.isEmpty() )
  16. return QwtGraphic();
  17.  
  18. QwtGraphic graphic;
  19. graphic.setDefaultSize( iconSize );
  20. graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
  21.  
  22. QPainter painter( &graphic );
  23. painter.setRenderHint( QPainter::Antialiasing,
  24. testRenderHint( QwtPlotItem::RenderAntialiased ) );
  25.  
  26. bool doShowLine = testLegendAttribute (QwtPlotCurve::LegendShowLine);
  27. bool doShowSymb = testLegendAttribute (QwtPlotCurve::LegendShowSymbol);
  28. bool doShowBrush = testLegendAttribute (QwtPlotCurve::LegendShowBrush);
  29. bool noAttribs = !(doShowLine || doShowSymb || doShowBrush);
  30.  
  31. const QPen curvePen = pen();
  32. const QwtSymbol* curveSymb = symbol();
  33.  
  34. if ( noAttribs || doShowBrush)
  35. {
  36. QBrush curveBrush = brush();
  37.  
  38. if ( curveBrush.style() == Qt::NoBrush && noAttribs )
  39. {
  40. if ( style() != QwtPlotCurve::NoCurve )
  41. {
  42. curveBrush = QBrush( curvePen.color() );
  43. }
  44. else if ( curveSymb && (curveSymb->style() != QwtSymbol::NoSymbol) )
  45. {
  46. curveBrush = QBrush( curveSymb->pen().color() );
  47. }
  48. }
  49.  
  50. if ( curveBrush.style() != Qt::NoBrush )
  51. {
  52. QRectF r( 0, 0, iconSize.width(), iconSize.height() );
  53. painter.fillRect( r, curveBrush );
  54. }
  55. }
  56.  
  57. if ( doShowLine )
  58. {
  59. if ( curvePen != Qt::NoPen )
  60. {
  61. // CADSWES FIX, Gnats 5864 ("Legend and plot line look different if
  62. // thickness is greater than one"). DON'T set the pen Cap Style.
  63. //
  64. //-- QPen pn = curvePen;
  65. //-- pn.setCapStyle( Qt::FlatCap );
  66. //-- painter.setPen( pn );
  67.  
  68. painter.setPen( curvePen );
  69. const double y = 0.5 * iconSize.height();
  70. QwtPainter::drawLine( &painter, 0.0, y, iconSize.width(), y );
  71. }
  72. }
  73.  
  74. if ( doShowSymb )
  75. {
  76. if ( curveSymb )
  77. {
  78. QRectF r( 0, 0, iconSize.width(), iconSize.height() );
  79. curveSymb->drawSymbol( &painter, r );
  80. }
  81. }
  82.  
  83. return graphic;
  84. }
To copy to clipboard, switch view to plain text mode