Mapping a ScrollArea to the ScrollBars of a QGraphicsView
-
Hello,
I have two QGraphicsViews that are placed on a QSplitter, and I implemented zooming functionality in the wheelEvent of the QGraphics class so I can zoom in and out of the image. When I zoom in at some point the scroll bars of each view appear.
However I would like to set the scrollbars of each view to not visible and be able to control the scrolling of each view(at the same time) through a scrollbar placed in the bottom of my main window. I am thinking maybe for this I need to set a ScrollArea as the widget that contains my splitter with the two views. But then how can I map that scroll bar to control the two views in the splitter when the zooming is big enough so that scrolling is needed?
Thanks.
-
No. What I would do, is just set the scrollBarPolicy of the graphicsViews to Qt::ScrollBarAlwaysOff, and then manually put a horizontal and a vertical scroll bar in your form. You can unfortunately not use QAbstractScrollArea::set*ScrollBar to set an external scrollbar; that method will move the scrollbar within the layout of the scroll area container. However, you can still synchronize the values of the (invisible) scrollbars of the graphics views and your own scroll bars.
Putting the graphicsViews in a QScrollArea will achieve nothing. You do not want to scroll the graphicsView widgets, but their contents.
-
@ Andre, Thanks for the reply!
Yes I have done it like that and it is working fine, however I'm having a bit of a problem I cant seem to get a hold of. I have been able to map the invisible scrollBar (in this case I use only the horizontal one) to my external Scrollbar at least in position so that when the invisible scrollbars would have appeared when zoomed in, my external scrollbar goes to the correct position and I can control the scrolling from there. The problem is the size of my scroll bar is not set according to how much I zoomed in or out like the "inivisible ones" act by default.
My question is how can I map the size of my scrollBar to be the same as the invisible ones so that the width of my scroll bar resizes according to how much I zoomed?
-
Here is almost everything needed for this post:
http://developer.qt.nokia.com/faq/answer/how_can_i_use_one_horizontal_scrollbar_to_scroll_several_qgraphicsviews