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. QGraphicsView and item moving issue

QGraphicsView and item moving issue

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.1k 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.
  • T Offline
    T Offline
    tarantulae
    wrote on last edited by
    #1

    When I have:

    1. QGraphicsView with a QGraphicsScene (without sceneRect() set)
    2. Add two QGraphicsObjects inside the QGraphicsScene (in this moment, the size of the scene is still smaller then the QGraphicsView viewport).
    3. When I move one Object the scene is resized and re-centered, but this causes the impression that both objects are being moved.

    Is there any way to avoid this ? Thanks !

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      sceneRect : QRectF
      This property holds the scene rectangle; the bounding rectangle of the scene.

      The scene rectangle defines the extent of the scene. It is primarily used by QGraphicsView to determine the view's default scrollable area, and by QGraphicsScene to manage item indexing.

      If unset, or if set to a null QRectF, sceneRect() will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).

      Access functions:

      QRectF sceneRect () const
      void setSceneRect ( const QRectF & rect )
      void setSceneRect ( qreal x, qreal y, qreal w, qreal h )

      this is the normal behavior ... set it in order to avoid this

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tarantulae
        wrote on last edited by
        #3

        Ok, but when I set the sceneRect(), the QGraphicsView doesn't adjusts the scene automatically when someone drags an object to the corner of the viewport. It seems that there is no way to have logic that automatically adjusts the scene size and also a behavior where the objects doesn't seems to move apart when someone moves them.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NicuPopescu
          wrote on last edited by
          #4

          I think you could: the visible growing effect occur until the scene rect will get greater or equal with the view's rect; so you need first to add to scene some dummy items(or move forth and back one of your objects) in all four directions just a little over the view's edges and keep scene rect (and the view's one ) unset to get it growing automatically and view adjusting its scrolling area as well

          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