Results 1 to 4 of 4

Thread: Click on a marker

  1. #1
    Join Date
    Dec 2015
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Click on a marker

    Hello! The plot (QwtPlot) contains many markers (QwtPlotMarker). How to determine which marker was clicked?

    To solve this problem, I changed the standard example of "event filter". After each click of the mouse, I check all the markers.
    If the marker is located close to the click, this marker has been pressed.

    Qt Code:
    1. void Plot::mousePressEvent(QMouseEvent *e)
    2. {
    3. QwtPlot::mousePressEvent(e);
    4.  
    5. const QwtPlotItemList& items = itemList();
    6. for ( QwtPlotItemIterator i = items.begin(); i != items.end(); ++i )
    7. {
    8. if ( (*i)->rtti() == QwtPlotItem::Rtti_PlotMarker )
    9. {
    10. QwtPlotMarker *m = static_cast<QwtPlotMarker*>(*i);
    11.  
    12. // The distance from the marker to the place a clicked
    13. float distance = sqrt( pow( (transform(QwtPlot::xBottom, m->value().x()) - e->pos().x()), 2 ) + pow( (transform(QwtPlot::yLeft, m->value().y()) - e->pos().y()), 2 ) );
    14.  
    15. if (distance <= 5)
    16. {
    17. qDebug() << "YEAP!";
    18. }
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    Is there a better solution?

  2. #2
    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: Click on a marker

    Quote Originally Posted by d1mbarus View Post
    Is there a better solution?
    Not out of the box - if you have to deal with many, many markers you might need to introduce some spatial ordered index ( f.e a quadtree ).

    Uwe

    PS: Using x * x is faster than pow(x, 2 ) and you can avoid the sqrt by comparing x * x + y * y against 25.

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

    d1mbarus (10th January 2016)

  4. #3
    Join Date
    Dec 2015
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Click on a marker

    Quote Originally Posted by Uwe View Post
    Not out of the box - if you have to deal with many, many markers you might need to introduce some spatial ordered index ( f.e a quadtree ).
    The number of markers is less than 10. Can you tell us more about the quadtree? I have not found information about quadtree.

  5. #4
    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: Click on a marker

    Quote Originally Posted by d1mbarus View Post
    The number of markers is less than 10.
    Then iterating over the complete list will never be a problem.

    Quote Originally Posted by d1mbarus View Post
    Can you tell us more about the quadtree? I have not found information about quadtree.
    https://en.wikipedia.org/wiki/Quadtree

    Uwe

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

    d1mbarus (10th January 2016)

Similar Threads

  1. Adding marker to scale widget
    By SeanM in forum Qwt
    Replies: 3
    Last Post: 18th August 2014, 20:47
  2. zooming and moving marker
    By temis in forum Qwt
    Replies: 2
    Last Post: 26th July 2012, 17:59
  3. Zooming the plot without the marker
    By raghvendramisra in forum Qwt
    Replies: 1
    Last Post: 17th May 2012, 18:24
  4. Marker and Scale
    By WXNSNW in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2008, 10:44
  5. Moving plot marker with the mouse
    By viridis in forum Qwt
    Replies: 2
    Last Post: 23rd September 2008, 21:39

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.