Question

I have three QGraphicsView s each one with a different scene. I am trying to scroll all the views when the user is scrolling one of them. The scrolling is carried out by the user dragging in the QGraphicsView widget which calls QGraphicsView::scrollContentsBy. (no scrollbars)

My first implementation: From scrollContentsBy I am calling centerOn for all the other views but this ends up into a recursive call of scrollContentsBy.

My second implementation: From scrollContentsBy I am calling scroll for all the other views but the view is not updated correctly (missing part of the scene). It does scroll correctly though.

I tried different versions on this but I can't find the solution. Any idea would be great.

Edit: I found the answer but I need to wait 3 more hours before to reply to my own question :)

Was it helpful?

Solution

I am glad that in fact I can answer my own question and share the answer with others. The only thing that you have to do, it is to create 2 scrollbars (one vertical and one horizontal) and to set these two scrollbars for all the QGraphicsView instances. When the user drag one picture all the view receive the same event and scrollContentsBy is called for each view. Easy when you know.

m_hScrollBar = new QScrollBar(Qt::Horizontal);

m_vScrollBar = new QScrollBar(Qt::Vertical);

m_srcView->setHorizontalScrollBar(m_hScrollBar);

m_srcView->setVerticalScrollBar(m_vScrollBar);

m_dstView->setHorizontalScrollBar(m_hScrollBar);

m_dstView->setVerticalScrollBar(m_vScrollBar);

m_diffView->setHorizontalScrollBar(m_hScrollBar);

m_diffView->setVerticalScrollBar(m_vScrollBar);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top