Results 1 to 8 of 8

Thread: A question about coordinate transform

  1. #1
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default A question about coordinate transform

    I reimplement the mousePressEvent and use QwtPlot::invTransform to transform the coordinate.But it don't work as I expected.

    Qt Code:
    1. void plot :: mousePressEvent(QMouseEvent *e)
    2. {
    3. if(e->button() == Qt::LeftButton)
    4. {
    5. QPointF temp = e->posF();
    6. QMessageBox::information(this,tr("information!"),tr("the original x posation is %1 and y posation is %2").arg(temp.x()).arg(temp.y()),QMessageBox::Ok|QMessageBox::Default,QMessageBox::NoButton,QMessageBox::NoButton);
    7. //picker->invTransform()
    8. temp.setX(this->invTransform(QwtPlot::xBottom,temp.x()));
    9. temp.setY(this->invTransform(QwtPlot::yLeft,temp.y()));
    10.  
    11. QMessageBox::information(this,tr("information!"),tr("changed x posation is %1 and y posation is %2").arg(temp.x()).arg(temp.y()),QMessageBox::Ok|QMessageBox::Default,QMessageBox::NoButton,QMessageBox::NoButton);
    12.  
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    well , it look just like 2013-05-23 07:00:57的屏幕截图.png2013-05-23 07:00:34的屏幕截图.png

    but the real coordinate in the axis is is not x=688.05 and y=553.371

  2. #2
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A question about coordinate transform

    Can anyone help me ?

  3. #3
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A question about coordinate transform

    Your code seems correct to me.
    How do you know that x=688.05 and y=553.371 isn't correct values?
    Post a screenshot maybe where it is clearly visible, it may give a pointer.
    Also it helps if you attach minimal compilable project.

  4. #4
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A question about coordinate transform

    because the value on the QwtPlotpicker donesn't is not 688.05 553.371... wait a moment , I 'll post a screenshot...


    Added after 1 41 minutes:


    3.png1.png1.png
    Last edited by lazy_learner; 24th May 2013 at 13:40.

  5. #5
    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: A question about coordinate transform

    Wrong widget: canvas != plot.

    You have to install an event filter for the canvas - or with Qwt 6.1 you can overload the mouse event handler of it. If you want to keep your code you have to translate the coordinates of the mouse click into coordinates that are relative to the canvas - f.e. with mapToGlobal() and mapFromGlobal() - or simply by subtracting the position of the canvas.

    Uwe

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

    lazy_learner (25th May 2013)

  7. #6
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A question about coordinate transform

    yes ,you're right. In the first version of my program. I solved this problem by subtract a certain value , but I don't know why and how it happen.Er.. But how can I know the position of the canvas ?

  8. #7
    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: A question about coordinate transform

    Use QWidget::pos() or QWidget::geometry() - the canvas is a child of the plot widget.

    Uwe
    Last edited by Uwe; 26th May 2013 at 21:22.

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

    lazy_learner (26th May 2013)

  10. #8
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A question about coordinate transform

    thank you~you're very helpful~

Similar Threads

  1. transform() vs pos() for QGraphicsItem
    By aalexei in forum Qt Programming
    Replies: 9
    Last Post: 14th November 2012, 00:34
  2. qt3d transform feedback
    By firnafin in forum Qt Programming
    Replies: 0
    Last Post: 28th June 2012, 14:54
  3. Replies: 1
    Last Post: 5th August 2011, 04:35
  4. Transform widget with the mouse
    By puch71 in forum Newbie
    Replies: 1
    Last Post: 31st January 2011, 08:36
  5. Distance Transform on a QImage
    By Franckesh in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 09:58

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.