Results 1 to 3 of 3

Thread: redraw the axes of a QwtPlot during a panning (QwtPlotPanner)

  1. #1
    Join Date
    Feb 2012
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default redraw the axes of a QwtPlot during a panning (QwtPlotPanner)

    I'm using QWT 6.0.1 RC5, QT 4.8.0

    I added a QwtPlotPanner in a QwtPlot and I would like axes were moving simultaneously to the shift of the canvas and not only once the panner is finished.

    Then I associated a slot to the signal move (int dx , int dy) of the QwtPlotPanner :

    note :cart is a QwtPlot.

    Qt Code:
    1. QwtScaleMap scaleMapTmpX = cart->canvasMap(QwtPlot::xBottom);
    2. scaleMapTmpX.setScaleInterval(cart->axisScaleDiv(QwtPlot::xBottom)->upperBound(),
    3. cart->axisScaleDiv(QwtPlot::xBottom)->lowerBound());
    4.  
    5. QwtScaleMap scaleMapTmpY = cart->canvasMap(QwtPlot::yLeft);
    6. scaleMapTmpY.setScaleInterval(cart->axisScaleDiv(QwtPlot::yLeft)->upperBound(),
    7. cart->axisScaleDiv(QwtPlot::yLeft)->lowerBound());
    8.  
    9. double zoomPlotDragLowerBoundX = cart->axisScaleDiv(QwtPlot::xBottom)->lowerBound();
    10. double zoomPlotDragUpperBoundX = cart->axisScaleDiv(QwtPlot::xBottom)->upperBound();
    11. double zoomPlotDragLowerBoundY = cart->axisScaleDiv(QwtPlot::yLeft)->lowerBound();
    12. double zoomPlotDragUpperBoundY = cart->axisScaleDiv(QwtPlot::yLeft)->upperBound();
    13.  
    14. double LowerBoundX = scaleMapTmpX.transform(zoomPlotDragLowerBoundX);
    15. double UpperBoundX = scaleMapTmpX.transform(zoomPlotDragUpperBoundX);
    16. double LowerBoundY = scaleMapTmpY.transform(zoomPlotDragLowerBoundY);
    17. double UpperBoundY = scaleMapTmpY.transform(zoomPlotDragUpperBoundY);
    18.  
    19. cart->setAxisScale(QwtPlot::yLeft, scaleMapTmpY.invTransform(LowerBoundY + dy) ,
    20. scaleMapTmpY.invTransform(UpperBoundY + dy) );
    21.  
    22. cart->setAxisScale(QwtPlot::xBottom, scaleMapTmpX.invTransform(LowerBoundX + dx) ,
    23. scaleMapTmpX.invTransform(UpperBoundX + dx ));
    24. cart->replot();
    To copy to clipboard, switch view to plain text mode 

    In the posted code the axes aren't correctly redraw (in partular the shift isn't conveted in the right scale). Do you have a solution?

    In the implementation of the signal move(int dx, int dy), dx and dy represent the offset in pixel or in another unit of measure?

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

    Default Re: redraw the axes of a QwtPlot during a panning (QwtPlotPanner)

    Quote Originally Posted by gaia86 View Post
    I added a QwtPlotPanner in a QwtPlot and I would like axes were moving simultaneously to the shift of the canvas and not only once the panner is finished.
    Then don't use QwtPlotPanner. Instead install an event filter for the plot canvas handling its mouse events. Translate them into calls of QwtPlot:.setAxisScale + QwtPlot::replot();

    But be aware of jumping scales ( modifiying the size of the canvas ) + potential performance issues for complex scenes.

    Uwe

  3. #3
    Join Date
    Dec 2011
    Posts
    60
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: redraw the axes of a QwtPlot during a panning (QwtPlotPanner)

    Very old thread and I'm not the OP, but I finally got around to implementing this, so I'll leave it here in case anyone is looking for an example.

    I handled it with a QwtPlotZoomer (m_zoomer) and update the zoom() based on the mouse movement while the middle mouse button is down. It's quite fast, even on large plots and is immune to changes in the plot size.

    I store the mouse drag location (m_mouseDragLocation) when the middle button is first pressed and then update it after each 1px movement during a drag operation.

    Then, inside QwtPlot::eventFilter()
    Qt Code:
    1. // MouseMove only fires while a mouse button is pressed
    2. if (event->type() == QEvent::MouseMove)
    3. {
    4. // User wants to pan the plot
    5. if (m_middleMouseDown)
    6. {
    7. // Get current zoom rectangle
    8. QRectF zoomRect = m_zoomer->zoomRect();
    9.  
    10. // Convert the change in position for the last drag (1px) from
    11. // pixel space to plot space.
    12. double deltaX = invTransform(QwtPlot::xBottom, m_mouseDragLocation.x()) - invTransform(QwtPlot::xBottom, cursor().pos().x());
    13. double deltaY = invTransform(QwtPlot::yLeft, m_mouseDragLocation.y()) - invTransform(QwtPlot::yLeft, cursor().pos().y());
    14.  
    15. // Update the zoom rect with the new values
    16. zoomRect.setX(zoomRect.x() + deltaX);
    17. zoomRect.setY(zoomRect.y() + deltaY);
    18. zoomRect.setWidth (zoomRect.width() + deltaX);
    19. zoomRect.setHeight(zoomRect.height() + deltaY);
    20.  
    21. // Store for continued dragging
    22. m_mouseDragLocation = cursor().pos();
    23.  
    24. // Set the zoom to its new position
    25. m_zoomer->zoom(zoomRect);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by alketi; 5th May 2020 at 19:47.

Similar Threads

  1. Graphic effects of QwtPlotPanner
    By mastupristi in forum Qwt
    Replies: 2
    Last Post: 2nd July 2019, 21:14
  2. Replies: 4
    Last Post: 10th June 2010, 13:31
  3. Replies: 1
    Last Post: 23rd February 2010, 07:25
  4. Panning
    By linuxdev in forum The GraphicsView Framework
    Replies: 3
    Last Post: 30th December 2008, 06:40
  5. Replies: 1
    Last Post: 3rd November 2008, 10:13

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.