Nominate our 2022 Qt Champions!

How to write a additional code, which has to get triggered at the Scroll event of the QGraphicsView

  • How to write a additional code at the Scroll event of the QGraphicsView. I want to do some additional operations in the scroll event of both the vertical and horizontal scroll bar.

  • I would do something as below (may be my suggestion as well):

    Derive QScrollBar to your own custom Scroll Bar and override the below methods per your requirement.
    virtual void mouseMoveEvent ( QMouseEvent * e )
    virtual void mousePressEvent ( QMouseEvent * e )
    virtual void mouseReleaseEvent ( QMouseEvent * e )
    virtual void sliderChange ( SliderChange change )

    QGraphicsView has two methods which will replace the existing Scroll Bars.
    void QAbstractScrollArea::setHorizontalScrollBar ( QScrollBar * scrollBar )
    void QAbstractScrollArea::setVerticalScrollBar ( QScrollBar * scrollBar )

    Replace the existing Scroll Bars with your custom Scroll Bar instances.


  • Why don't you just connect to the scrollBar's valueChanged() signal?

  • Wow! Andre - why didn't it strike my mind?

    I did learn something new today - now that is a smarter way - thanks!


  • Thanks for your replies. I used scrollContentsBy(int dx, int dy) function. Did overriding.

  • Jothi - suggest you to edit the subject with [SOLVED] as the issue is solved.

Log in to reply