Results 1 to 3 of 3

Thread: QwtPlotZoomer - zooming in on a cursor position

  1. #1
    Join Date
    Jul 2009
    Qt products
    Unix/X11 Windows

    Default QwtPlotZoomer - zooming in on a cursor position

    I'm using Qwt6 SVN and I want to have a "Zoom In" action in a right-click context menu, which should take a rectangle of some size (say, 100x100 px) around the cursor position and zoom in on that. I'm using QwtPlotZoomer (I know that there's also QwtPlotMagnifier, but I need a single zoom stack).

    I can't figure out what to pass to QwtPlotZoomer::zoom(const QRectF &rect), all I have is a mouse position as provided by customContextMenuRequested(QPoint) signal.

    Thanks in advance!

    P.S. I tried constructing a rectangle around that position and passing that, but it didn't work (didn't think it would).

  2. #2
    Join Date
    Feb 2006
    Munich, Germany
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotZoomer - zooming in on a cursor position

    I wouldn't recommend to use QwtPlotZoomer for your way of zooming. Simply write an event filter for the plot canvas where you catch context menu events. If you want to zoom in translate your zoom rectangle into scale coordinates ( using the scale maps ) and call setAxisScale(). For the zoom stack use QStack.


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

    torrentss (20th August 2010)

  4. #3
    Join Date
    Jul 2009
    Qt products
    Unix/X11 Windows

    Default Re: QwtPlotZoomer - zooming in on a cursor position

    I'm already using two full-blown zoomers (one on each axis pair), so reimplementing that manually would be no fun.
    I don't think I need the event filter - the context menu shows up fine. I just store the position the mouse cursor was at when the menu was opened.

    I think I solved this problem with the following code in the action handler (thanks to your tip about scale maps). Note: plot_ is QwtPlot, last_menu_pos_ is the parameter of customContextMenuRequested() as attached to plot_, and zoomer_left_ / zoomer_right_ are the two zoomers.

    Qt Code:
    1. QPoint mouse_pos =>canvas()->mapFromGlobal(
    4. // Choose a rectangle around mouse pos and zoom to it.
    5. QRectF mouse_rect(mouse_pos.x() - 50, mouse_pos.y() - 50, 100, 100);
    7. QRectF scale_rect_left;
    8. {
    9. const QwtScaleMap xMap =>canvasMap(>xAxis());
    10. const QwtScaleMap yMap =>canvasMap(>yAxis());
    11. scale_rect_left = QRectF(
    12. QPointF(xMap.invTransform(mouse_rect.x()), yMap.invTransform(mouse_rect.y())),
    13. QPointF(xMap.invTransform(mouse_rect.right()), yMap.invTransform(mouse_rect.bottom())) );
    14. }
    16. QRectF scale_rect_right;
    17. {
    18. const QwtScaleMap xMap =>canvasMap(>xAxis());
    19. const QwtScaleMap yMap =>canvasMap(>yAxis());
    20. scale_rect_right = QRectF(
    21. QPointF(xMap.invTransform(mouse_rect.x()), yMap.invTransform(mouse_rect.y())),
    22. QPointF(xMap.invTransform(mouse_rect.right()), yMap.invTransform(mouse_rect.bottom())) );
    23. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTextEdit restore cursor position
    By artur231 in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2014, 23:02
  2. Cursor Position in scene
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 12th March 2010, 16:31
  3. Display cursor position in QGraphicsView
    By dbrmik in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2009, 16:06
  4. Replies: 6
    Last Post: 30th May 2007, 10:25
  5. Cursor scene position
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 14:51

Tags for this Thread


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.