c++qtqtcharts

How to enable zooming in QtCharts?


I want to be able to zoom in my QtCharts using the mouse.

The best way to zoom using the mouse would be by drawing rectangles and adjusting the view to the new smaller rectangle.

How Can I implement this in QtCharts?

Highcharts has a very similar example and it looks quite nice:

enter image description here


Solution

  • This functionality is provided by QChartView:

    QChartView v;
    v.setRubberBand(QChartView::HorizontalRubberBand);
    

    There is also zooming out functionality bound to your mouse:

    If the left mouse button is pressed and the rubber band is enabled, ... the rubber band is displayed on the screen. This enables the user to select the zoom area.

    Otherwise use the zooming functions in QChart.