PDA

View Full Version : invTransform not working



ppp
3rd June 2015, 07:22
Hello,
I am trying to work out how the invTransform function works. But I guess I misunderstood something.

Here is what I tried already:



#include <QApplication>

#include <qwt_plot.h>
#include <qwt_plot_curve.h>

int main( int argc, char** argv ){

QApplication app( argc, argv );

QwtPlot plot;
QwtPlotCurve curve;
QVector<QPointF> list;

list.append( QPointF(2,1.5) );
list.append( QPointF(3,5) );
list.append( QPointF(4,3.4) );

curve.setSamples( list );
curve.attach( &plot );

qDebug() << "invTransform(): " << plot.invTransform( curve.xAxis(), 3 );
qDebug() << "invTransform(): " << plot.canvasMap( QwtPlot::xBottom ).invTransform( list[1].x() );

plot.show();

qDebug() << "invTransform(): " << plot.invTransform( curve.xAxis(), 3);

return app.exec();
}


The Console outputs:



invTransform(): 3
invTransform(): 3
invTransform(): -3


Can someone please tell me why it's not working?!
I appreciate it.

Uwe
3rd June 2015, 08:10
You have to call replot first - otherwise you don't have a valid scale and mapping between scale and paint device coordinates will never work.

Uwe

ppp
3rd June 2015, 08:23
Well, if I add



plot.replot();


right before all the invTransform() functions the console outputs:



invTransform(): 1.97826
invTransform(): 1.97826
invTransform(): 1.96078


It should output a five. Those 1.9something looks to me like the lowerBound...

Uwe
3rd June 2015, 08:32
invTransform maps from widget to scale coordinates and a value of 3 is close to the beginning on an interval that is about [0, width() ]. So no surprise, that you are close to the lower bound.

Uwe

ppp
3rd June 2015, 08:46
OK. And how can I get the right return value?
I need to find out what's the y value to a corresponding x value...

Uwe
3rd June 2015, 09:04
OK. And how can I get the right return value?
I need to find out what's the y value to a corresponding x value...
By recalling what you have learned in school - this is basic maths completely unrelated to Qwt ( f.e see QLineF::pointAt() if you don't know how to calculate a point on a line ).
You could also have a look at the curvetracker example, what does something similar.

Uwe

ppp
3rd June 2015, 14:03
I fixed my problem with the idea like in the curvetracker example without invTransform.
Thank you.