Results 1 to 7 of 7

Thread: How to rescale the QwtPlotZoomer->canvas

  1. #1
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default How to rescale the QwtPlotZoomer->canvas

    Hey community,


    I have the following problem. I am constructing a simple 2D-Plot. At the begining I construct a QwtPlot etc. . In an other thread I compute a Vector from a function or whatever. Then this Thread is calling the "preview::createCurve()" methode to draw the curve to the constructed plot. Normally the plot ist automatically rescaled (if i do not set the axisscales manually) to the plotted curve. Since I want to provide zooming in my plots, I have to tell the ZoomingClass the initial ScaleCoordinates of the plotted curve (so the coordinates to which the zoomer goes back when you press the right mouse button). => how can I do that?

    Another question is: What if I plot another curve in the same Plot. Will he rescale the plot canvas automatically, when I have rescaled the ZoomingClasScale before ?

    here the code and sorry for my crappy english:

    Qt Code:
    1. #include "curve.h"
    2.  
    3. class Zoomer: public QwtPlotZoomer
    4. {
    5. public:
    6. Zoomer(QwtPlotCanvas *canvas):
    7. QwtPlotZoomer(canvas)
    8. {
    9. setRubberBandPen(QPen(Qt::darkGreen, 1.5, Qt::SolidLine));
    10. }
    11.  
    12. virtual QwtText trackerTextF(const QPointF &pos) const
    13. {
    14. QColor bg(Qt::white);
    15. QwtText text = QwtPlotZoomer::trackerTextF(pos);
    16. text.setBackgroundBrush( QBrush( bg ));
    17. return text;
    18. }
    19.  
    20. virtual void rescale()
    21. {
    22. QwtPlotZoomer::rescale();
    23. }
    24. };
    25.  
    26. curve::curve(QWidget *parent, const QString &title) : QWidget()
    27. {
    28. QFont font("Arial" , 12);
    29. plot = new QwtPlot;
    30. plotGrid = new QwtPlotGrid;
    31. plotGridLayout = new QGridLayout;
    32. plotZoom = new Zoomer(plot->canvas());
    33.  
    34. //plotTitle
    35. plotTitle.setFont(font);
    36. plotTitle.setText(title);
    37. //plotGrid
    38. plotGrid->enableXMin(true);
    39. plotGrid->enableYMin(true);
    40. plotGrid->setMajPen(QPen(Qt::black,1,Qt::SolidLine));
    41. plotGrid->setMinPen(QPen(Qt::darkGray,0,Qt::DotLine));
    42. plotGrid->attach(plot);
    43. //Plot
    44. plot->setTitle(plotTitle);
    45. plot->setMaximumSize(800,800);
    46. plot->setMinimumSize(400,400);
    47. plot->setCanvasLineWidth(2);
    48. plot->setCanvasBackground(QBrush(QColor(240,240,240), Qt::SolidPattern));
    49. plot->setAxisFont(0, font);
    50. plot->setAxisFont(2, font);
    51. plot->axisWidget(0)->setMargin(0);
    52. plot->axisWidget(2)->setMargin(0);
    53. plot->plotLayout()->setAlignCanvasToScales(true);
    54.  
    55. plotGridLayout->addWidget(plot);
    56. this->setLayout(plotGridLayout);
    57. }
    58.  
    59. //plotCurve
    60. void curve::createCurve(const QVector<QPointF> &vector, const QString &title)
    61. {
    62. plotCurve = new QwtPlotCurve(title);
    63. //Std Color = blue
    64. plotCurve->setPen(QPen(Qt::blue, 1.5));
    65. plotCurve->setSymbol(new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(Qt::black), QSize(3, 3)));
    66.  
    67. //Std_style = lines, antialiased
    68. plotCurve->setCurveAttribute(QwtPlotCurve::Fitted);
    69. plotCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    70.  
    71. //Points = vector
    72. plotCurve->setSamples(vector);
    73. //Std_Plot = plot
    74. plotCurve->attach(plot);
    75.  
    76. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    Right mouse button click is equal to QwtPlotZoomer::zoom(0).

    Not sure about the second question. No idea when you want to add the second curve.
    If you add two curves one after another - then just call setZoomerBase() after adding both curves and everything should work fine.
    If you want to add second curve when first one is zoomed in and make sure zoomer gets updated correctly - that's a bit more complex but still possible.

  3. #3
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    If you want to add second curve when first one is zoomed in and make sure zoomer gets updated correctly - that's a bit more complex but still possible.
    I think this is, what I want. How can I solve this problem ?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,195
    Thanked 847 Times in 796 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    There are only two ways how an axis scale can be set:
    • explicitly by setAxisScale or setAxisScaleDiv
    • implicitely by the auto scaler

    Autoscaling is enabled in the default setting of QwtPlot and executed each time replot ( updateAxes ) is called. As soon as you explicitly assign a scale autoscaling gets disabled until you re-enable it with setAxisAutoScale().

    The zoomer doesn't have a different API for setting the scales - all it can do is to use setAxisScale. So whenever the zoomer changes a scale autoscaling gets disabled.

    When you add a new curve and want to run the autoscaler again you have to do:

    Qt Code:
    1. plot->setAxisAutoScale( axisId, true );
    2. plot->replot();
    To copy to clipboard, switch view to plain text mode 
    Usually you don't want to keep a zoom stack ( the history of the zoom rectangles ) starting with the scales from your previous
    run of the autoscaler. To reinitialize the zoomer with the new scales you have to do:

    Qt Code:
    1. doReplot = false;
    2. zoomer->setZoomBase( doReplot );
    To copy to clipboard, switch view to plain text mode 
    The mystery behind the doReplot flag is, that setAxisScale/setAxisAutoScale only assign the parameters for the calculation of the new scale, but the scales are calculated later ( replot/updateAxes ). So you have to do a replot before you reinitialize the zoomer to avoid, that it gets initialized with the previous scales.

    In the code snippet above doReplot is set to false. This is only done because you already did the the replot above and you don't need to do it twice.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    revellix (7th October 2011)

  6. #5
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    Thanks, now I got it.

    Another little question: is it possible to change the MajorTickLabels manually ? F.e. I want the Unit to be at the next to last MajorTick .... xAxisTicks[ 0 1 2 µm 3 ] ?

  7. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    Overload QwtScaleDraw::drawLabel, you can decide here what is displayed over the major ticks.

  8. The following user says thank you to Spitfire for this useful post:

    revellix (7th October 2011)

  9. #7
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to rescale the QwtPlotZoomer->canvas

    this one is too hard for me now ... too noobish

Similar Threads

  1. QwtPlotZoomer zooming off the plot canvas
    By BettaUseYoNikes in forum Qwt
    Replies: 1
    Last Post: 26th June 2011, 11:38
  2. Replies: 1
    Last Post: 13th May 2011, 18:12
  3. Replies: 1
    Last Post: 7th March 2011, 08:34
  4. Replies: 0
    Last Post: 9th August 2010, 10:46
  5. Automatic rescale QwtPlotMarker
    By gpsgek in forum Qwt
    Replies: 0
    Last Post: 23rd May 2010, 16:26

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.