hi friends,

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

http://qtcenter.org/wiki/index.php?t...ng_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

Qt Code:
  1. QRectF visibleArea = mapToScene(rect()).boundingRect();
  2.  
  3. //Get the scene area
  4. QRectF sceneBounds = sceneRect();
  5.  
  6. double boundX = visibleArea.width() / 2.0;
  7. double boundY = visibleArea.height() / 2.0;
  8. double boundWidth = sceneBounds.width() - 2.0 * boundX;
  9. double boundHeight = sceneBounds.height() - 2.0 * boundY;
  10.  
  11. //The max boundary that the centerPoint can be to
  12. QRectF bounds(boundX, boundY, boundWidth, boundHeight);
  13.  
  14. if(bounds.contains(centerPoint)) {
  15. //We are within the bounds
  16. CurrentCenterPoint = centerPoint;
  17. } else {
  18. //We need to clamp or use the center of the screen
  19. if(visibleArea.contains(sceneBounds)) {
  20. //Use the center of scene ie. we can see the whole scene
  21. CurrentCenterPoint = sceneBounds.center();
  22. } else {
  23.  
  24. CurrentCenterPoint = centerPoint;
  25.  
  26. //We need to clamp the center. The centerPoint is too large
  27. if(centerPoint.x() > bounds.x() + bounds.width()) {
  28. CurrentCenterPoint.setX(bounds.x() + bounds.width());
  29. } else if(centerPoint.x() < bounds.x()) {
  30. CurrentCenterPoint.setX(bounds.x());
  31. }
  32.  
  33. if(centerPoint.y() > bounds.y() + bounds.height()) {
  34. CurrentCenterPoint.setY(bounds.y() + bounds.height());
  35. } else if(centerPoint.y() < bounds.y()) {
  36. CurrentCenterPoint.setY(bounds.y());
  37. }
  38.  
  39. }
  40. }
  41.  
  42. //Update the scrollbars
  43. centerOn(CurrentCenterPoint);
To copy to clipboard, switch view to plain text mode 
is where they are centering the viewport but while zooming only positive half was visible and pan is not working

please help me