Results 1 to 7 of 7

Thread: invTransform not working

  1. #1
    Join Date
    Jun 2015
    Posts
    4

    Default invTransform not working

    Hello,
    I am trying to work out how the invTransform function works. But I guess I misunderstood something.

    Here is what I tried already:

    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include <qwt_plot.h>
    4. #include <qwt_plot_curve.h>
    5.  
    6. int main( int argc, char** argv ){
    7.  
    8. QApplication app( argc, argv );
    9.  
    10. QwtPlot plot;
    11. QwtPlotCurve curve;
    12. QVector<QPointF> list;
    13.  
    14. list.append( QPointF(2,1.5) );
    15. list.append( QPointF(3,5) );
    16. list.append( QPointF(4,3.4) );
    17.  
    18. curve.setSamples( list );
    19. curve.attach( &plot );
    20.  
    21. qDebug() << "invTransform(): " << plot.invTransform( curve.xAxis(), 3 );
    22. qDebug() << "invTransform(): " << plot.canvasMap( QwtPlot::xBottom ).invTransform( list[1].x() );
    23.  
    24. plot.show();
    25.  
    26. qDebug() << "invTransform(): " << plot.invTransform( curve.xAxis(), 3);
    27.  
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    The Console outputs:

    Qt Code:
    1. invTransform(): 3
    2. invTransform(): 3
    3. invTransform(): -3
    To copy to clipboard, switch view to plain text mode 

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

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

    Default Re: invTransform not working

    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

  3. #3
    Join Date
    Jun 2015
    Posts
    4

    Default Re: invTransform not working

    Well, if I add

    Qt Code:
    1. plot.replot();
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. invTransform(): 1.97826
    2. invTransform(): 1.97826
    3. invTransform(): 1.96078
    To copy to clipboard, switch view to plain text mode 

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

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

    Default Re: invTransform not working

    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

  5. #5
    Join Date
    Jun 2015
    Posts
    4

    Default Re: invTransform not working

    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...

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

    Default Re: invTransform not working

    Quote Originally Posted by ppp View Post
    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

  7. #7
    Join Date
    Jun 2015
    Posts
    4

    Default Re: invTransform not working

    I fixed my problem with the idea like in the curvetracker example without invTransform.
    Thank you.

Similar Threads

  1. Replies: 2
    Last Post: 24th April 2015, 15:47
  2. Replies: 7
    Last Post: 24th September 2012, 07:17
  3. Working with map
    By naptizaN in forum Newbie
    Replies: 4
    Last Post: 28th August 2012, 12:57
  4. MVC example not working
    By yyiu002 in forum Newbie
    Replies: 1
    Last Post: 30th June 2010, 00:07
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

Tags for this Thread

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.