Results 1 to 6 of 6

Thread: QwtPolar picker

  1. #1
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QwtPolar picker

    Hi folks!
    I need to display the degree and the radius value on a label every time the mouse is moved on the polar canvas. With QwtPlotPicker this is easy, but i don't see any QwtPolarPicker to do that!

    I need to implement something like QwtPlotPicker?

    Thanks for the help.

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

    Default Re: QwtPolar picker

    Well, you could derive from QwtPicker and overload "trackerText(const QPoint &pos)".

    Using the scale maps ( QwtPolarPlot::scaleMap() ) you should be able to calculate a QwtPolarPoint from pos and translate into a QString.

    Uwe

  3. #3
    Join Date
    Mar 2006
    Posts
    8
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPolar picker

    Has anyone been able to do this? Been trying to do this for a day now, but do not end up with any numbers that make any sense...

  4. #4
    Join Date
    Dec 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: QwtPolar picker

    I post here a chunk of my code. It's not the most clear way to do that, but i mean... it works!

    I use the eventFilter trapping the mouse move event on the entire canvas and translate the pixel position with the radial distance from the plot center.

    I have an object that extends OQbject and thakes a QwtPolarCanvas as argument.

    Qt Code:
    1. PolarMouseTrackerTool::PolarMouseTrackerTool(QwtPolarCanvas *canv) : QObject(canv)
    2. {
    3. isActive = true;
    4. canvas = canv;
    5. canvas->setMouseTracking(true);
    6. canvas->installEventFilter(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    And the rest of the class is this:

    Qt Code:
    1. bool PolarMouseTrackerTool::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if ((event->type() != QEvent::MouseMove && event->type() != QEvent::MouseButtonRelease && event->type() != QEvent::MouseButtonDblClick) || !isActive)
    4. {
    5. return QObject::eventFilter(obj, event);
    6. }
    7.  
    8. QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
    9. if (mouseEvent == NULL)
    10. return false;
    11.  
    12. QPoint mousePos = mouseEvent->pos();
    13. QwtPolarPlot *polarPlot = canvas->plot();
    14.  
    15. if (polarPlot == NULL)
    16. return false;
    17.  
    18. QwtScaleMap radiusMap = polarPlot->scaleMap(QwtPolar::ScaleRadius);
    19.  
    20. double sDist = radiusMap.s2() - radiusMap.s1();
    21. double dDist = radiusMap.p2() - radiusMap.p1();
    22.  
    23. //The pole center (in pixel)
    24. QPoint pole = polarPlot->plotRect().center().toPoint();
    25.  
    26. //translate
    27. translatePosWithCanvasCenter(pole, mousePos);
    28.  
    29. //Pitagora
    30. double a = qAbs(qAtan(mousePos.y() / (mousePos.x() * 1.0)));
    31. double r = qSqrt((qPow(mousePos.x(), 2)) + qPow(mousePos.y(), 2));
    32. translateAzimuthWithCanvasCenter(mousePos, a);
    33.  
    34. //radix mapping
    35. r = (r * sDist) / dDist;
    36.  
    37. if (event->type() == QEvent::MouseMove)
    38. emit signalMoved(a, r);
    39.  
    40. if (event->type() == QEvent::MouseButtonDblClick)
    41. {
    42. emit signalDblClicked(a, r, mouseEvent->button());
    43. emit signalDblClicked(mouseEvent->pos(), mouseEvent->button());
    44. }
    45.  
    46. if (event->type() == QEvent::MouseButtonRelease)
    47. emit signalClicked(a, r, mouseEvent->button());
    48.  
    49. return true;
    50. }
    51.  
    52. void PolarMouseTrackerTool::translatePosWithCanvasCenter(const QPoint &canvasCenter, QPoint &pos)
    53. {
    54. pos.setX(pos.x() - canvasCenter.x());
    55. pos.setY(canvasCenter.y() - pos.y());
    56. }
    57.  
    58. void PolarMouseTrackerTool::translateAzimuthWithCanvasCenter(const QPoint &pos, double &azimuth)
    59. {
    60. if (pos.x() >= 0 && pos.y() >= 0) //Quadrant 1
    61. {
    62. //Nothing to do
    63. }
    64. else if (pos.x() < 0 && pos.y() > 0) //Quadrant 4
    65. {
    66. azimuth = (M_PI / 2.0) + ((M_PI / 2.0) - azimuth);
    67. }
    68. else if (pos.x() <= 0 && pos.y() <= 0) //Quadrant 3
    69. {
    70. azimuth = M_PI + azimuth;
    71. }
    72. else //Quadrant 2
    73. {
    74. azimuth = (M_PI * (3.0 / 2.0)) + ((M_PI / 2.0) - azimuth);
    75. }
    76.  
    77. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPolar picker

    Well your class is not really derived from QwtPicker, but the basic idea of event filtering is the same and if it works for you ...

    Uwe

  6. #6
    Join Date
    Mar 2006
    Posts
    8
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPolar picker

    Thanks a lot! This works for me. I tried to put the code in my own picker class, but couldn't get the numbers quite correct, propably because of small differences in the cursor position. Also this made the tracker text show up correctly (if I put return QObject::eventFilter(obj, event); at the end of the eventfilter function.) Before it would get stuck when set to AlwaysOn.

    Lars

Similar Threads

  1. Printing with QwtPolar
    By grymhild in forum Qwt
    Replies: 1
    Last Post: 1st September 2010, 06:41
  2. Picker text
    By MuzZviman in forum Qwt
    Replies: 1
    Last Post: 2nd June 2010, 09:49
  3. QwtPolar 0.1.0
    By Uwe in forum Qt-based Software
    Replies: 1
    Last Post: 12th October 2009, 09:40
  4. Plot Picker x=0
    By sun in forum Qwt
    Replies: 2
    Last Post: 7th October 2008, 07:43
  5. QwtPolar 0.0.1
    By Uwe in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2008, 16:46

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.