How to reset chartview after zoom and scroll?



  • I have a chartview with zoom and scroll.
    when i zoom in and scroll then hit the escape key.

    the chartview resets, but it doesnt scroll back to the original position.
    is there a function like zoomReset that reverses the scroll?

    void ChartView::keyPressEvent(QKeyEvent *event)
    {
        switch (event->key()) {
        case Qt::Key_Plus:
            chart()->zoomIn();
            break;
        case Qt::Key_Minus:
            chart()->zoomOut();
            break;
        case Qt::Key_Escape:
           chart()->zoomReset();
            break;
        case Qt::Key_Left:
            chart()->scroll(-1000, 0);
            break;
        case Qt::Key_Right:
            chart()->scroll(1000, 0);
            break;
        case Qt::Key_Up:
            chart()->scroll(0, 1000);
            break;
        case Qt::Key_Down:
            chart()->scroll(0, -1000);
            break;
        default:
            QGraphicsView::keyPressEvent(event);
            break;
        }
    }
    


  • Actually in Qt documentation it's written in the description of zoomReset() function that
    Resets the series domains to what they were before any zoom method was called.

    Which means that the series of operation should be 1) Zoom 2) Scroll right/left/up/down.
    If you perform above sequence of operation then zoomReset() will work.

    It seems that it is correct also if you have performed scroll operation first then it is also obvious that you want to analyze in scrolled Area only so zoomReset() will just then resets zooming only...



  • thanks. managed to get it to work, by zooming in ever so slightly before scrolling.


Log in to reply