Qt 6.12 LTS is out! See what's new in the release
blog
How to zoom in or out of a Chart using QCustomPlot but using push buttons rather than a mouseWheel
-
The QCustomPlot library offers users the ability to zoom in and out of the graph drawn on the custom chart when they enable the Zoom interaction. Now What I want is for to zoom in an out of the graph in the same manner but with two Push Buttons. One for zooming in and another for zooming out.
How would I go on about something like that? I just want the user to be able to zoom in into the widget that contains the graphs or zoom out when one of those buttons are clicked.
Is there a way in the library that allows me to manually trigger the zooming effect or do I perhaps scale the widget itself to emulate the zooming effect?
-
Does this help? (it is code from a custom QWidget)
void ImageView::keyPressEvent(QKeyEvent* e) { const QPointF mouseLocation(mapFromGlobal(QCursor::pos())); bool handled = false; switch (e->key()) { case Qt::Key_Plus: case Qt::Key_Equal: // Handle Ctrl+= and Ctrl++ as Zoom in if (e->modifiers() & Qt::ControlModifier) { zoom(mouseLocation, 1); handled = true; } break; case Qt::Key_Minus: // Handle Ctrl+- as Zoom out if (e->modifiers() & Qt::ControlModifier) { zoom(mouseLocation, -1); handled = true; } break; default: break; } if (!handled) QWidget::keyPressEvent(e); }