Search code examples
qtqgraphicsview

synchronize scrollbar in Qt


I have 2 graphicsview each with a separate scrollbar, as seen in the image. I wonder how I can synchronize, so that the move one the other moves too.

thanks


Solution

  • That is quite simple, just connect each view's scroll bar's valueChanged(int) signal (or sliderMoved(int)) signal to the other view's scroll bar's setValue(int) slot, like so:

    connect(view1->horizontalScrollBar(), SIGNAL(valueChanged(int)), view2->horizontalScrollBar(), SLOT(setValue(int)));
    connect(view2->horizontalScrollBar(), SIGNAL(valueChanged(int)), view1->horizontalScrollBar(), SLOT(setValue(int)));