[Qt-interest] scrolling multiple QGraphicsViews

Glenn Hughes ghughes02138 at gmail.com
Mon Apr 12 01:26:44 CEST 2010


Hey all,

I'm trying to figure out how to scroll multiple QGraphicsViews. The
reason I think I need multiple QGraphicsViews is that the items inside
of them may be clipped independently in the Y axis, but they all need
to scroll together in the X axis. In other words, they may wind up
with individual scroll bars in the Y axis, but they should have one
common scroll bar in the X axis.

I've found one example that almost works... but not quite.
http://qt.nokia.com/developer/faqs/faq.2007-06-08.0800842041
It's connecting a single scrollbar to two different views...
However the approach doesn't quite work.
The problem is calling "scroll" on the views scrolls all children as
well, including the vertical scroll bars of the views. I don't want to
do that, I just want to scroll the views themselves and leave the virt
scrollbars where they are. I tried making a subclass of QGraphicsView
and exposing scrollContentsBy. This almost does what I want (it
scrolls the content of the QGraphicsView, but leaves the vertical
scrollbars where they should be) but unfortunately it doesn't
"actually" scroll the items because the offset (xoffset) isn't getting
updated internally in QAbstractScrollArea, so as soon as the window
repaints for some other reason the graphics snap back to their
original location.

I've also looked into simply connecting a single scrollbar to both
views, but that won't work either since it sets the parent of the
scrollbar, and assumes ownership.

This is all pretty confusing to me. It looks to me at this point like
there's no way of successfully driving the scroll position of a
QAbstractScrollArea from the "outside" i.e. from any widget other than
its built-in scrollbars... That's a pretty nasty limitation if true.

Opinions? Ideas?

Thanks as always.
Glenn



More information about the Qt-interest-old mailing list