Results 1 to 3 of 3

Thread: QwtPlot - Copying before using with QwtPlotRenderer

  1. #1
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlot - Copying before using with QwtPlotRenderer

    I have a custom QwtPlot that I want to render inside a pdf document. (see use-case image)
    QwtPlotRenderer looks to be perfect for doing this, the only thing is that I need to edit a few thing on the Plot before rendering it.

    Right now I just modify the original plot directly before rendering it, which cause the interface to also be modified.
    Here is an example :
    Qt Code:
    1. void WorkoutCreator::exportWorkoutToPdf() {
    2.  
    3. /// TODO: Add Title, remove background image, increase margins
    4. ui->widget_plot->setContentsMargins(20,20,20,20);
    5.  
    6. QwtPlotRenderer renderer;
    7. renderer.exportTo( ui->widget_plot, "shapes.pdf" );
    8.  
    9. /// Revert plot back to normal (best would be to copy to a new QwtPlot and trash it after this function is done..)
    10. ui->widget_plot->setContentsMargins(0,0,0,0);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 


    I would like to copy the QwtPlot with all it's objects (it's just a normal QwtPlot with a few QwtPlotShapeItem)
    I have tried to code a copy Constructor, but I'm having problem copying the QwtPlotShapeItem.

    Is there an easier solution that I'm missing?
    Thanks a lot!

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

    Default Re: QwtPlot - Copying before using with QwtPlotRenderer

    You can't copy widgets ( or QwtPlotItems ). Your only option - beside modify + export + revert of the original one - is to create a second ( invisible ) one.
    The plot items could be temporarily attached to the second one and reattached to the first one again, when the export is done.

    Uwe

  3. #3
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlot - Copying before using with QwtPlotRenderer

    Oh nice idea to have a second invisible one!
    Thanks Uwe and many thanks for Qwt hopefully I can repay you sometime soon!

    This did the trick:
    Qt Code:
    1. void WorkoutCreator::exportWorkoutToPdf() {
    2.  
    3. /// ui->widget_plot_report is a copy of ui->widget_plot formatted for reports - widget is setVisible(false)
    4. ui->widget_plot_report->setTitle(workout.getName());
    5. ui->widget_plot_report->setContentsMargins(20,20,20,20);
    6.  
    7. QwtPlotRenderer renderer;
    8. renderer.exportTo( ui->widget_plot_report, "shapes.pdf" );
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 15th December 2014, 10:26
  2. QwtPlotRenderer for multiple QwtPlot
    By Momergil in forum Qwt
    Replies: 1
    Last Post: 18th January 2013, 11:09
  3. QwtPlotRenderer::renderDocument()
    By jrm in forum Qwt
    Replies: 1
    Last Post: 31st October 2012, 07:10
  4. Possible bug in QwtPlotRenderer
    By BettaUseYoNikes in forum Qwt
    Replies: 1
    Last Post: 29th November 2011, 08:00

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.