jackajack
jackajack

Reputation: 153

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

Upvotes: 3

Views: 1980

Answers (1)

Anthony
Anthony

Reputation: 8788

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)));

Upvotes: 6

Related Questions