Results 1 to 20 of 21

Thread: QGraphicsView scale question.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView scale question.

    I believe i have found the "why". In the documentation, it is said this:
    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).


    Which means, if my scene is created containing a QImage of 1600x1200 and if i scale down this image to 800x600, the sceneRect will still be 1600x1200. So i just tried to do a "grphScProcessed->setSceneRect(pPicture->boundingRect());" right after my item is scaled down, but same problem. Any clue please?

    Pierre.

  2. #2
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView scale question.

    ok i think i have finally found what i needed. Here is what i do now, right after changing the scale of my item in the scene:

    Qt Code:
    1. pPicture = grphVwOriginalPicture->items().first();
    2. pPicture->scale(.5, .5);
    3. cTopLeft = pPicture->mapToScene(pPicture->boundingRect().topLeft());
    4. cBotRight = pPicture->mapToScene(pPicture->boundingRect().bottomRight());
    5. grphScOriginal->setSceneRect(cTopLeft.x(), cTopLeft.y(), cBotRight.x()-cTopLeft.x(), cBotRight.y()-cTopLeft.y());
    To copy to clipboard, switch view to plain text mode 

    It seems it's sufficient to set up the scene's view rect to the right rect...

    Marcel, thanks for all your help, it's because of you i finally understood what the mappedTo / mappedFrom methods do

    Pierrre.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView scale question.

    I was just looking over your last 2 posts...
    Good you found a solution...

    BTW:
    setSceneRect( item->boundingRect( )) did not work because boundingRect remains unscaled. It always remains at the original value. That is why the mapping is needed.

    Another thing to remember is that when you create the raster it is placed in the scene at position (0,0).
    When you scale it, it will shrink, but the top left position is still at (0, 0), that is why the center would not work. I thought that is what you wanted - to see the entire scaled picture, not to see it AND be centered .

    Your solution, set scene rect will shrink the scene size, but I guess that's ok, because you'll set it again if you zoom in/out...

    Regards

Similar Threads

  1. Replies: 1
    Last Post: 15th March 2007, 20:45
  2. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  4. Efficient Scaling and Rotating of QGraphicsView
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 12th December 2006, 16:28
  5. QGraphicsView scale function
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2006, 14:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.