tags:

views:

218

answers:

1

Hi all!

I have different types of QWidgets into a DockWindow:

  • 1 Qwt plot
  • 1 QWidget
  • 3 QGraphicsView

And I need scrolling all of them at the same time with the same scrollbar when I zoom in. I know two solutions for this:

  • Create one scrollbar and connect it to each widget.
  • Create one scrollArea and manipulate all the widgets.

What is the best solution to this? Do you know any scrollArea tutorial?

Thank you so much

+1  A: 

I would try to make it so that each of the items that needs to scroll in concert is inside its own QScrollArea. I would then put all those widgets into one widget, with a QScrollBar underneath (and/or to the side, if needed).

Designate one of the interior scrolled widget as the "master", probably the plot widget. Then do the following:

  • Set every QScrollArea's horizontal scroll bar policy to never show the scroll bars.
  • The master QScrollArea's horizontalScrollBar()'s rangeChanged( int min, int max ) signal to a slot that sets the main widget's horizontal QScrollBar to the same range. Additionally, it should set the same range for the other scroll area widget's horizontal scroll bars.
  • The horizontal QScrollBar's valueChanged( int value ) signal should be connected to every scroll area widget's horizontal scroll bar's setValue( int value ) slot.
  • Repeat for vertical scroll bars, if doing vertical scrolling.

There is one place where I think this could go wrong, and that is mouse-wheel scrolling. You could solve this in a couple of ways. One would be to connect all the scrolling areas to a slot that triggers when their value changes, which updates all the other scroll bars. The other would be to install event filters on those widgets, and either ignore the scroll or process it with the main scroll bars.

Caleb Huitt - cjhuitt
Thank you so much cjhuitt.
Drewen