Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mapping a ScrollArea to the ScrollBars of a QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

Mapping a ScrollArea to the ScrollBars of a QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sergex
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sergex
        wrote on last edited by
        #3

        @ 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?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Can't you use the rangeChanged() signal for that?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sergex
            wrote on last edited by
            #5

            Yeah that worked for me, thanks.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sergex
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved