Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart horizontal only zoom?
Qt 6.11 is out! See what's new in the release blog

QChart horizontal only zoom?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 1.7k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    martonmiklos
    wrote on last edited by
    #1

    I am working on a digital waveform display where only the horizontal zooming makes sense. Is there any way to restrict the zoom to the horizontal scale. I have seen the
    zoomIn(const QRectF &) member, but I would like to avoid the continous rectangle calculation.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      martonmiklos
      wrote on last edited by
      #2

      For the posterity:

      
      void ZoomableChartView::wheelEvent(QWheelEvent *event)
      {
          if (event->angleDelta().y() > 0) {
              zoomX(2, event->pos().x() - chart()->plotArea().x());
              qWarning() << chart()->plotArea();
          } else if (event->angleDelta().y() < 0) {
              zoomX(0.9, event->pos().x() - chart()->plotArea().x());
          }
      }
      
      void ZoomableChartView::zoomX(qreal factor, qreal xcenter)
      {
          QRectF rect = chart()->plotArea();
          qreal widthOriginal = rect.width();
          rect.setWidth(widthOriginal / factor);
          qreal centerScale = (xcenter / widthOriginal);
      
          qreal leftOffset = (xcenter - (rect.width() * centerScale) );
      
          rect.moveLeft(rect.x() + leftOffset);
          chart()->zoomIn(rect);
      }
      
      
      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 Extensions
      • Unsolved