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 only zoom the X axis

QChart only zoom the X axis

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 226 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.
  • D Offline
    D Offline
    Deneguil
    wrote on last edited by
    #1

    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

    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