Results 1 to 3 of 3

Thread: How do I dynamically adjust the position of QwtPlotMarker using mouse click & drag ?

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How do I dynamically adjust the position of QwtPlotMarker using mouse click & drag ?

    Now, I'm drawing the QwtPlotMarker on QwtPlot taking user input values from the spinbox. But I want to adjust the position of QwtMarker on mouse click & drag and place it in the required position(Y-Axis). How can I implement this?

    Thank you.

  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 do I dynamically adjust the position of QwtPlotMarker using mouse click & dra

    You can do it in several different ways.

    In general, you want to install event filter on the plot's canvas to be able to intercept mouse move/button events.
    Then on click you need to find which (if any) marker is there at the position of mouse press.
    When you have a marker you can then adjust its value during mouse move (you need to replot the plot each time you change marker value to see it move).

    If replotting is time consuming, instead of moving actual marker, create a widget that will look like marker and parent it to the canvas.
    This widget should be hidden when not dragged.
    On mouse press hide actual marker, show the widget (remember to replot after hidding the marker).
    On mouse move move the widget.
    On mouse release hide the widget, set new value on the marker and show it (remember to replot).

  3. #3
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How do I dynamically adjust the position of QwtPlotMarker using mouse click & dra

    hey, you have already plotted that curve, so now Symbol by the click of mouse, for that use---->

    initialize this
    Qt Code:
    1. QwtPlotMarker *mark[1000];
    2. int i=0;
    3. QPoint pt;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void mousePressEvent(QMouseEvent *event){
    2. mark[i]=new QwtPlotMarker;
    3. mark[i]->setSymbol(your_symbol);
    4. mark[i]->setValue(pt.x(),pt.y());
    5. mark[i]->attach(your_plot);
    6. i++;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Now wherever you click on the curve it will plot it.

  4. The following user says thank you to sonulohani for this useful post:

    rawfool (8th June 2012)

Similar Threads

  1. Replies: 3
    Last Post: 11th May 2011, 18:57
  2. Get mouse position on click?
    By N3wb in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2010, 23:33
  3. how to get the position of mouse click on a label
    By qt_user in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2010, 09:14
  4. Replies: 1
    Last Post: 10th July 2009, 09:54
  5. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 04:56

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.