I have a plot that uses a legend positioned initially with QwtPlot::RightLegend and then set to QwtPlot::ExternalLegend.

I want to render the plot to the clipboard but the legend rectangle ends up being painted at position 0,0 and not where I actually see it in my widget.

Here's the rendering code:
Qt Code:
  1. QClipboard *clipboard = QApplication::clipboard();
  2. QwtPlotRenderer renderer;
  3. QImage img(this->size(), QImage::Format_ARGB32);
  4. QPainter painter(&img);
  5. renderer.render(this, &painter, this->rect());
  6. clipboard->setImage(img);
To copy to clipboard, switch view to plain text mode 

I tried to reposition the legend to QwtPlot::RightLegend but then I naturally get it in the separate right section as you would see it in the widget, which is not what I want.

How can I make the legend rectangle painted in it's actual position?