Search code examples
c++qtqwt

qwt plot move curve after rescale or zoom on cursor


I have a classic curve in a plot and I want to set a zoom at the cursor position with the wheel mouse event. For that I want to :

  • Set a rescale : QwtPlotMagnifier::rescale(factor); (this is done and works)

  • Set the center of my plot to the position of my cursor (I find anything on this part, on the documentation, stackoverflow or on others websites)

I don't know if there's an other way to proceed and if you have any suggestions ..

Thanks !


Solution

  • So I find a solution which works perfectly, I finally set a zoom like the google maps zoom.

    The solution is :

    • catch the widget wheel event in the plot magnifier
    • create a private method in the plot magnifier rescale_on_cursor(double factor, int x_cursor, int y_cursor, QSize parent_size)

    In the widget wheel event you will call your method. The factor will be 0,9 or 1,1 (unzoom or zoom), (x, y) the cursor position and QSize the size of the parent widget.

    The main idea is to derivate the qwt_plotMagnifier::rescale() and to modify the step where you define the new scale, you will set a percentage of the scale which is equals to the percent of the cursor position.

    If x_cursor is equals to 20% of the parent size you will setAxisScale(20%(zoom), 80%(zoom)).