PDA

View Full Version : problem with pan zooming in QGraphicsView



wagmare
8th April 2013, 12:06
hi friends,

I just implement the pan zooming of QGraphicsView by following this example in this forum

http://qtcenter.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_ Zooming


but this pan zooming was behaving different when i change the coordinates of the scene from (0, 0, 1000, 1000) to ( -500, -500, 1000, 1000)
i tried to identify where to correct but failed


QRectF visibleArea = mapToScene(rect()).boundingRect();

//Get the scene area
QRectF sceneBounds = sceneRect();

double boundX = visibleArea.width() / 2.0;
double boundY = visibleArea.height() / 2.0;
double boundWidth = sceneBounds.width() - 2.0 * boundX;
double boundHeight = sceneBounds.height() - 2.0 * boundY;

//The max boundary that the centerPoint can be to
QRectF bounds(boundX, boundY, boundWidth, boundHeight);

if(bounds.contains(centerPoint)) {
//We are within the bounds
CurrentCenterPoint = centerPoint;
} else {
//We need to clamp or use the center of the screen
if(visibleArea.contains(sceneBounds)) {
//Use the center of scene ie. we can see the whole scene
CurrentCenterPoint = sceneBounds.center();
} else {

CurrentCenterPoint = centerPoint;

//We need to clamp the center. The centerPoint is too large
if(centerPoint.x() > bounds.x() + bounds.width()) {
CurrentCenterPoint.setX(bounds.x() + bounds.width());
} else if(centerPoint.x() < bounds.x()) {
CurrentCenterPoint.setX(bounds.x());
}

if(centerPoint.y() > bounds.y() + bounds.height()) {
CurrentCenterPoint.setY(bounds.y() + bounds.height());
} else if(centerPoint.y() < bounds.y()) {
CurrentCenterPoint.setY(bounds.y());
}

}
}

//Update the scrollbars
centerOn(CurrentCenterPoint);
is where they are centering the viewport but while zooming only positive half was visible and pan is not working

please help me