Results 1 to 13 of 13

Thread: Zooming scene

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Zooming scene

    Hi guys,

    I am using the QGraphicsScene/View classes in my app. I have a moving rectangle that can be resized and using this rectangle I can choose which part of the scene should be zoomed in? Do you have an idea how to zoom in just a small rectangle from the scene.
    QGraphicsView::scale etc, zooms the whole scene. But I need to zoom only the rectangle.
    Any ideas?

    Thank you.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    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: Zooming scene

    Something like a magnifying glass?

    I don't think you can do this using only the Graphics View API.
    There is no way of zooming only in a part of the scene.

    Maybe you can achieve something with QGraphicsScene::render. You know, maybe you can render that area to a pixmap and display that in a rectangle?

    Another, more complicated solution( that, however, I am sure it will work ) is to create another graphics view for the very same scene.
    This graphics view should be the size of your magnifying rectangle. Also, it should be floating, i.e. not contained in any layout, it will just follow the mouse.Then you can scale the contents of this view as much as you want, since it won't affect the other view.

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene

    On the contrary, it's very possible. I've done this myself as a simple research toy, but can't find the example right now. The magnifying glass is a QGraphicsItem that renders the contents of the scene underneath in paint() using QGraphicsScene::render(), but makes sure to hide itself before and show itself after, to avoid the magnifier itself from being "magnified" into itself.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  4. #4
    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: Zooming scene

    Quote Originally Posted by Bitto View Post
    On the contrary, it's very possible. I've done this myself as a simple research toy, but can't find the example right now. The magnifying glass is a QGraphicsItem that renders the contents of the scene underneath in paint() using QGraphicsScene::render(), but makes sure to hide itself before and show itself after, to avoid the magnifier itself from being "magnified" into itself.
    But isn't there any quality loss at higher zoom factors, considering we hold the result in a pixmap?

    Regards

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Zooming scene

    I have an idea (though not revolutionary)
    Create one more view with same scene and the dimension same as that of required rectangle. Turn off the scrollbars and other unnecessary things.
    Here comes the complicated part.
    Now obtain the sceneRect that the rectangle(or probably the view itself) covers on the background view. Using this scale the new view using proper calculations and do position it properly using centerOn() or someting similar.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #6
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Zooming scene

    Actually this is nice question. We can request our "Mr. GraphicsView" - Andreas to provide this functionality in the upcoming qt versions.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  7. #7
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene

    I might be missing something here, but isn't it as simple as calling
    Qt Code:
    1. fitInView(selection, Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 
    selection being the rectangle in scene coords.

  8. #8
    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: Zooming scene

    Quote Originally Posted by spud View Post
    I might be missing something here, but isn't it as simple as calling
    Qt Code:
    1. fitInView(selection, Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 
    selection being the rectangle in scene coords.
    Yes, but this only if you implement the magnifying glass as a separate view for the scene.

    Regards

  9. #9
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Zooming scene

    Quote Originally Posted by spud View Post
    I might be missing something here, but isn't it as simple as calling
    Qt Code:
    1. fitInView(selection, Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 
    selection being the rectangle in scene coords.
    Yes you are right. I missed this simple thing
    In that case i guess my idea will work.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  10. #10
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene

    Hi guys,

    Thank you very much for interest and help. I suppose that fitInView(QRectF) will do what I need, but will also consider others ideas.


    Thank you.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  11. #11
    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: Zooming scene

    In that case i guess my idea will work.
    Take a look at post #2.

    Regards

  12. #12
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Zooming scene

    Quote Originally Posted by marcel View Post
    Take a look at post #2.

    Regards
    Right. Guess it should be "our" idea or rather our independent ideas. Sorry , i failed to read yours while "skimming" This was unintentional
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  13. #13
    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: Zooming scene


    No problem. I know you didn't see it.
    Anyway, at first I didn't think it would work either.


    Regards

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. can I get another QGraphicsView's scene?
    By sincnarf in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2007, 21:41
  3. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 11:27
  4. Replies: 3
    Last Post: 11th March 2007, 13:04
  5. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51

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.