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. Scrolling the contents of a GraphicsView
Forum Updated to NodeBB v4.3 + New Features

Scrolling the contents of a GraphicsView

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.9k 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 everyone,

    I have a few questions regarding the GraphicsView behavior. I am displaying an image that is in a scene as usual.

    First I want to know if I'm right thinking this:
    Basically I am doing QGraphicsView::scale(x, x), setting QGraphicsView::NoAnchor, so if x is 2 for example, the scene is twice as big in both directions, but the top left point is the same, so my viewport is displaying the top left area which is in this case 1/4 of the new scaled area…is this correct or do I have it all wrong??

    Then when I scale my view, I want to be able to control what area of the image I show in the viewport, so how can I scroll the scene to specific values to fit in my viewport exactly the area of the image I want to display??
    To scroll the scene I tried doing:

    horizontalScrollBar()->setValue(dx);
    verticalScrollBar()->setValue(dy);

    Assuming I calculated the values dx and dy to specify what to show in the viewport, but it's not scrolling anything..

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

      I've tried a few things and I think if I get the following right, things should work as I want them to.
      So what I'm doing is:

      1. I draw a rubberband rectangle on my image. I calculate the center point of that rectangle and save those coordinates.
      2. Then I do a scale transform to the view to fit the rubberband rectangle I selected previously to fit in the whole viewport.
      3. then I use the function:
        QGraphicsView::centerON(centerPoint) // centerPoint being the coordinates I saved in #1.

      Now my question is, I think the coordinates I saved in #1 through the mouse events (i.e. event->pos()) in press and release events are in View coordinates. So if I map those to scene coordinates with:

      QGraphicsView::mapToScene(x, y);

      and save that point, then after the scaling transformation doing centerOn(centerPoint) should center the viewport in the exact same point of the scene, just now the scene is scaled but the center point is the same..Is this logic right? For now I don't think its centering the viewport where I want it to so I think somewhere I'm missing something.

      Could someone please help me get on the right track??

      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