#189 Curve legend line width incorrect at high dpi


Using QwtPlotRenderer to render a plot to a painter with high DPI (e.g. 1200) causes the legend icon to have incorrect line width. To reproduce, create a plot with a legend and curves that have the LegendShowLine attribute set. Set the pen for the curves to have a non-zero line width. Render the plot to a high DPI painter (e.g. using renderToDocument at 1200 dpi). The result is that the legend icons for those curves are drawn with a very small line width - small enough that you cannot see the dots in a dotted line.

This is with Qwt 6.1.0 (was not a problem with 6.0.1).

See the attached example program for an illustration of the problem.

From examining the code it seems that when the QwtGraphic is rendered, the transform of the painter is reset and the old transform applied to the path only (qwtExecCommand when doMap == true) so the scale that gets the line width into the correct dpi is lost. Removing the RenderPensUnscaled attribute in the legend icon stops that from happening so my current workaround is to subclass QwtPlotCurve, override the legendIcon method and set that attribute to false.

1 Attachments


  • Josh

    Josh - 2013-06-06

    .pro file to build the example

  • Uwe Rathmann

    Uwe Rathmann - 2013-06-12

    The implementation of QwtPlotCurve::legendIcon explicitly decides not to scale the pens of the icon. Of course this is not what you need and your workaround that changes this decision is the right one for your situation.

    On screen the icon gets scaled into the geometry of the legend item, where you don't want have pens with a different width as what you have for the symbols and curve lines on the canvas. Guess this is the reason behind setting QwtGraphic::RenderPensUnscaled.

    But in case of QwtPlotRenderer there is a second scaling according to the resolution of the paint device that should affect the pens on canvas and legend in the same way.

    Needs to be fixed, but how to solve this in a clean way - maybe by having 2 flags instead of RenderPensUnscaled. Need more time to think about this ...

    • Josh

      Josh - 2013-06-13

      Seems that there is a transform applied to the painter in QwtGraphic::render that is combined with the original transform in this routine. The original transform on the painter is what has the scale for the DPI and needs to be maintained. Maybe rather than combining the two transforms in this routine pass the second transform into the qwtExecCommand and only apply it when QwtGraphic::RenderPensUnscaled is not specify. So in the case of RenderPensUnscaled it uses only the original transform, otherwise it combines them and uses the combined transform.

  • Uwe Rathmann

    Uwe Rathmann - 2013-06-12
    • assigned_to: Uwe Rathmann
    • Group: -->
  • Uwe Rathmann

    Uwe Rathmann - 2014-09-15
    • status: open --> closed
  • Uwe Rathmann

    Uwe Rathmann - 2014-09-15

    A fix has been added, that tries to avoid the internal scaling between control point rectangle and the coordinates of the target rectangle - however respects the scaling of the pens because of the initial setup of the painter transformation.

    Fixed in all branches >= 6.1

    One note: when drawing to a vector graphics format, the resolution of the paint device is only relevant for raster graphics ( QImage/QPixmap ) - like a spectrogram. For the usual use case - a plots with curves - a higher resolution will have no relevant effect as the resulting PDF is fully scalable without any loss in quality.

    Last edit: Uwe Rathmann 2014-09-15


Cancel  Add attachments

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks