PDA

View Full Version : Zooming in QGraphicsView



JonathanForQT4
11th April 2007, 16:32
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:



if(this->viewport()->width()>this->viewport()->height())
increaseZoom = this->viewport()->height()/m_deltaMouseZoomY;
else
increaseZoom = this->viewport()->width()/m_deltaMouseZoomX;

double offSetX = this->viewport()->width() - m_deltaMouseZoomX;
double offSetY = this->viewport()->height() - m_deltaMouseZoomY;

scale(increaseZoom, increaseZoom);

this->verticalScrollBar()->setSliderPosition(mapFromScene(m_zoomInStartPointS cene).y()-this->viewport()->height()+(offSetY/2));
this->horizontalScrollBar()->setSliderPosition(mapFromScene(m_zoomInStartPointS cene).x()-this->viewport()->width()+(offSetX/2));


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.

nmather
12th April 2007, 21:55
Hi, I wonder if QGraphicsView::centerOn() would be of any use to you?

JonathanForQT4
13th April 2007, 13:27
thanks, was the right suggestion :)

aamer4yu
17th April 2007, 05:50
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 :)