Results 1 to 4 of 4

Thread: Strange QwtPlotRenderer behaivor - axes scales are reset on rendering

  1. #1
    Join Date
    Feb 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Strange QwtPlotRenderer behaivor - axes scales are reset on rendering

    I have a weird problem with QwtPlotRenderer. I need to export a plot to file. The plot itself renders properly (it is also inserted as a widget into a tab in my program). However, when I tried to render the plot using QwtPlotRenderer renderTo or renderDocument methods, I have found that the scales of both axes are always set to 0 to 100. At the same time, exportTo method of QwtPlotRenderer works correctly, both with autoscaling and setting scales in code. I have looked through Qwt sources, found that exportTo method calls renderDocument after showing QFileDialog::getSaveFileName, copied most of the exportTo code to my program and finally found that the renderDocument method requires a call to static method of QFileDialog to work properly.

    The following code works as expected:

    Qt Code:
    1. QwtPlotRenderer renderer;
    2. QFileDialog::getSaveFileName(NULL);
    3. renderer.renderDocument(plot, "test.svg", QSizeF(100, 100));
    To copy to clipboard, switch view to plain text mode 

    This code does not:

    Qt Code:
    1. QwtPlotRenderer renderer;
    2. renderer.renderDocument(plot, "test.svg", QSizeF(100, 100));
    To copy to clipboard, switch view to plain text mode 

    QFileDialog::getOpenFileName or QFileDialog::getExistingDirectory may be used instead of QFileDialog::getSaveFileName. The effect does not depend on the file format (I have tested PNG, SVG and PDF). I am using Qt 5.2.1 and Qwt 6.1.0 under Windows 7, C++ compiler is MinGW 4.8.0 32-bit.

  2. #2
    Join Date
    Feb 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Strange QwtPlotRenderer behaivor - axes scales are reset on rendering

    Update: I have found that substituting QFileDialog::getSaveFileName(NULL) line with

    Qt Code:
    1. QDialog* d = new QDialog();
    2. d->exec();
    To copy to clipboard, switch view to plain text mode 

    also works, but when d->show() is used instead of d->exec(), the scales are reset.

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

    Default Re: Strange QwtPlotRenderer behaivor - axes scales are reset on rendering

    QDialog::exec() starts a recursive event loop, with the effect, that pending events are processed earlier. Guess a QCoreApplication::processEvents() instead of QDialog::exec would have the same effect.
    But what these events are and why they are changing the scale ranges can be found out best with the debugger.

    Note, that 0-100 is not the default axis range. If it is not the result of the autoscaler there must be code in your application setting it, that is running because of an event.

    Uwe

  4. #4
    Join Date
    Feb 2014
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Strange QwtPlotRenderer behaivor - axes scales are reset on rendering

    Yes, QCoreApplication::processEvents() works, but I have also found that calling QwtPlot::replot() before rendering the plot have the same effect. This code produces a normally looking image:

    Qt Code:
    1. QwtPlotRenderer renderer;
    2. plot->replot();
    3. renderer.renderDocument(plot, fileName, QSizeF(100, 100));
    To copy to clipboard, switch view to plain text mode 

    I have tested two cases, in the first the scales are set to 0-1 and 0-180, and in the second there is no code setting the scales. The whole block of code creating the plot is within a single method and looks like this:

    Qt Code:
    1. QwtPlot* plot = new QwtPlot();
    2. plot->setAxisScale(QwtPlot::xBottom, 0, 180);
    3. plot->setAxisScale(QwtPlot::yLeft, 0, 1);
    4. QwtPlotCurve* curve = new QwtPlotCurve();
    5. curve->setTitle("Test");
    6. curve->setPen(Qt::blue, 2 );
    7. curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
    8. curve->setSamples(data->getProbabilityCurve());
    9. curve->attach(plot);
    10. QwtPlotRenderer renderer;
    11. plot->replot();
    12. renderer.renderDocument(plot, fileName, QSizeF(100, 100));
    To copy to clipboard, switch view to plain text mode 

    Commenting plot->replot() call leads to scales reset. Commenting plot->setAxisScale calls has no effect on resetting.

Similar Threads

  1. QwtPlotRenderer::renderDocument()
    By jrm in forum Qwt
    Replies: 1
    Last Post: 31st October 2012, 08:10
  2. Replies: 5
    Last Post: 17th August 2012, 00:31
  3. Possible bug in QwtPlotRenderer
    By BettaUseYoNikes in forum Qwt
    Replies: 1
    Last Post: 29th November 2011, 09:00
  4. Problems with QwtPlotRenderer from Qwt 6
    By mariposa in forum Qwt
    Replies: 24
    Last Post: 6th October 2010, 14:08
  5. Replies: 1
    Last Post: 9th February 2010, 13:11

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.