Results 1 to 4 of 4

Thread: Zooming in QGraphicsView

  1. #1
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Zooming in QGraphicsView

    Haven't been able to get this down pat....kinda feel like a noob because of this, so I thought I'd post in this area.

    I use a rubberband to enlarge the scene using qgraphicsview's scale.
    here's the code for it:

    Qt Code:
    1. if(this->viewport()->width()>this->viewport()->height())
    2. increaseZoom = this->viewport()->height()/m_deltaMouseZoomY;
    3. else
    4. increaseZoom = this->viewport()->width()/m_deltaMouseZoomX;
    5.  
    6. double offSetX = this->viewport()->width() - m_deltaMouseZoomX;
    7. double offSetY = this->viewport()->height() - m_deltaMouseZoomY;
    8.  
    9. scale(increaseZoom, increaseZoom);
    10.  
    11. this->verticalScrollBar()->setSliderPosition(mapFromScene(m_zoomInStartPointScene).y()-this->viewport()->height()+(offSetY/2));
    12. this->horizontalScrollBar()->setSliderPosition(mapFromScene(m_zoomInStartPointScene).x()-this->viewport()->width()+(offSetX/2));
    To copy to clipboard, switch view to plain text mode 

    This code is almost right, but sometimes you need to adjust the scroll bars just a little so that whatever was in the rubberband stays in centred in the viewport.

    many thanks to anyone who can figure out why this is so close but off by a couple of clicks on the the scroll bars.

  2. #2
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Zooming in QGraphicsView

    Hi, I wonder if QGraphicsView::centerOn() would be of any use to you?
    Qpsycle -- open-source modular music studio built with Qt

  3. The following user says thank you to nmather for this useful post:

    JonathanForQT4 (13th April 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Zooming in QGraphicsView

    thanks, was the right suggestion

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zooming in QGraphicsView

    By the way, did u happen to use QGraphicsView::fitInView() ??
    u can easily set a rect from the scene to the whole view... as if to zoom thru rubberbanding...
    hope it will b useful to you

Similar Threads

  1. Simulating Video on QLabel or QGraphicsView
    By forrestfsu in forum Qt Programming
    Replies: 9
    Last Post: 21st March 2007, 11:39
  2. Replies: 3
    Last Post: 11th March 2007, 14:04
  3. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 12:04
  4. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 09:51
  5. QGraphicsView scale function
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2006, 15: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.