Results 1 to 3 of 3

Thread: Patterned Qwt Legend Line and Plot Line look different if thickness is greater than 1

  1. #1
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Patterned Qwt Legend Line and Plot Line look different if thickness is greater than 1

    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 

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

    Default Re: Patterned Qwt Legend Line and Plot Line look different if thickness is greater th

    If you prefer to keep the cap style from the curve sure. To be honest I can't remember the reason behind explicitly setting FlatCap - maybe because of trying to get rid of the extra pixels at the ends, that make drawing the line inaccurate.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    philw (30th March 2017)

  4. #3
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Patterned Qwt Legend Line and Plot Line look different if thickness is greater th

    Oh wow. Uwe, that's interesting.

    We didn't intend to set a Qt::PenCapStyle on our QwtPlotCurves' pens. We do want our curves to be as precise as possible, and would want to stick with Qt::FlatCap. We aren't explicitly doing anything with cap style, but I am understanding that a defaulted constructed QPen -- or one constructed from a color or pen style (e.g. Dotted) -- has a cap style of Qt::SquareCap. (We must be assigning a QPen like that to our QwtPlotCurves, but I haven't found that in our code yet).

    I DO see that when I force our QwtPlotCurves to have the Qt::FlatCap cap style -- see below -- the QwtLegend does show pen styles (e.g. Dotted) consistently with the plotted curve (with my modified code omitting the setting of the legend line's cap style -- see my prior post). So that explicit setting of Qt::FlatCap in QwtPlotCurve::legendIcon() I found seems to be unnecessary (at least now, in Qwt 6.1.3) [using Qt 5.5.1].

    Qt Code:
    1. QPen curvePen = pen();
    2. curvePen.setCapStyle (Qt::FlatCap);
    3. setPen (curvePen);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to draw a line anywhere on qwtpolar plot
    By vishaal_sss in forum Qwt
    Replies: 0
    Last Post: 23rd December 2014, 07:23
  2. Replies: 3
    Last Post: 22nd January 2014, 06:08
  3. Replies: 1
    Last Post: 29th September 2013, 09:12
  4. Replies: 2
    Last Post: 14th March 2012, 09:27
  5. QwtPlot line thickness
    By maluedo in forum Qwt
    Replies: 4
    Last Post: 12th March 2010, 16:13

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.