QChart only zoom the X axis
Unsolved
General and Desktop
-
Hello, I am currently making a scatter chart which needs to be zoomable on the X axis only. So far I have this code that I've adapted from the zoomline example
mapChart::mapChart(QGraphicsItem* parent, Qt::WindowFlags wFlags) : QChart(parent, wFlags) { grabGesture(Qt::PanGesture); grabGesture(Qt::PinchGesture); } bool mapChart::sceneEvent(QEvent *event) { if(event->type() == QEvent::Gesture) return gestureEvent(static_cast<QGestureEvent*>(event)); if(event->type() == QEvent::GraphicsSceneMouseDoubleClick){ QChart::zoomReset(); return true; } return QChart::event(event); } bool mapChart::gestureEvent(QGestureEvent *event) { if(QGesture * gesture = event->gesture(Qt::PanGesture)) { QPanGesture * pan = static_cast<QPanGesture*>(gesture); QChart::scroll(-(pan->delta().x()), 0); } if(QGesture * gesture = event->gesture(Qt::PinchGesture)) { QPinchGesture * pinch = static_cast<QPinchGesture*>(gesture); if(pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) QChart::zoom(pinch->scaleFactor()); } return true; }
However it also zooms the Y axis which I don't want. I've thought about overriding the zoom method and calculating the correct range for the X axis myself but then I'd need to do something similar to the pan which I'd like to avoid if possible.
Is there a way to only zoom on the X axis without overriding the zoom() method ?
Thank you