7

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

feedc0de
  • 3,646
  • 8
  • 30
  • 55
  • Did you see this zoom example http://doc.qt.io/qt-5/qtcharts-zoomlinechart-example.html? – demonplus Sep 02 '16 at 07:29
  • @demonplus I tried that but it only lets me move the chart using arrow keys and zoom very slow using + and - keys. Mouse interaction does not work! – feedc0de Sep 02 '16 at 07:37

1 Answers1

12

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.

Jason C
  • 38,729
  • 14
  • 126
  • 182
Lifeisabug
  • 366
  • 2
  • 6