Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to zoom in or out of a Chart using QCustomPlot but using push buttons rather than a mouseWheel
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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kokoy
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by
      #2

      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);
          }
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved