Question posted to the QtCentre / Qwt forum. 3-27-2017.
Patterned Qwt Legend Line and Plot Line look different if thickness is greater than one.
http://www.qtcentre.org/threads/68045
Note [4-20-2017]: See the subsequent revision to address this problem -- making both plot canvas curves and legend items show the "lighter" pattern appearance which previously had been shown in legend items. This is described on this webpage:
|
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().
The two following screenshots show the discrepancy. Both have a line width of 2. Dotted, and Dashed:
Here's a closer look at the problem. The "fixed" version matches what is shown on the plot:
The following show a fix -- effectively commenting out this line in QwtPlotCurve::legendIcon():
Instead of actually modifying QwtPlotCurve::legendIcon(), we lifted that implementation out of that class, and implemented a modified version in our QwtPlotCurve subclass.
// virtual from QwtPlotCurve QwtGraphic SlotCurve::legendIcon (int index, // (ignore, only one) const QSizeF& iconSize) const { // call base class method //-- QwtGraphic graphic = QwtPlotCurve::legendIcon (index, iconSize); // Note [Phil, 3-2017, RW 7.1, Qwt 6.1.3, Qt 5.5.1, Gnats 5864]: // The following code is adapted from QwtPlotCurve::legendIcon(). // See the fix for Gnats 5864, below ("Legend and plot line look // different if thickness is greater than one"). Q_UNUSED( index ); if ( iconSize.isEmpty() ) return QwtGraphic(); QwtGraphic graphic; graphic.setDefaultSize( iconSize ); graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); QPainter painter( &graphic ); painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) ); bool doShowLine = testLegendAttribute (QwtPlotCurve::LegendShowLine); bool doShowSymb = testLegendAttribute (QwtPlotCurve::LegendShowSymbol); bool doShowBrush = testLegendAttribute (QwtPlotCurve::LegendShowBrush); bool noAttribs = !(doShowLine || doShowSymb || doShowBrush); const QPen curvePen = pen(); const QwtSymbol* curveSymb = symbol(); if ( noAttribs || doShowBrush) { QBrush curveBrush = brush(); if ( curveBrush.style() == Qt::NoBrush && noAttribs ) { if ( style() != QwtPlotCurve::NoCurve ) { curveBrush = QBrush( curvePen.color() ); } else if ( curveSymb && (curveSymb->style() != QwtSymbol::NoSymbol) ) { curveBrush = QBrush( curveSymb->pen().color() ); } } if ( curveBrush.style() != Qt::NoBrush ) { QRectF r( 0, 0, iconSize.width(), iconSize.height() ); painter.fillRect( r, curveBrush ); } } if ( doShowLine ) { if ( curvePen != Qt::NoPen ) { // CADSWES FIX, Gnats 5864 ("Legend and plot line look different if // thickness is greater than one"). DON'T set the pen Cap Style. // //-- QPen pn = curvePen; //-- pn.setCapStyle( Qt::FlatCap ); //-- painter.setPen( pn ); painter.setPen( curvePen ); const double y = 0.5 * iconSize.height(); QwtPainter::drawLine( &painter, 0.0, y, iconSize.width(), y ); } } if ( doShowSymb ) { if ( curveSymb ) { QRectF r( 0, 0, iconSize.width(), iconSize.height() ); curveSymb->drawSymbol( &painter, r ); } } return graphic; } |
---