deca5423
21st January 2010, 23:46
I've ported a project from 4.5 to 4.6 because I wanted the improved performance for QGraphicsView. However, I noticed that centerOn doesnt appear to work properly, while it was 100% perfect in 4.5. It appears QGraphicsView does some calculation where it tries to show as much of the scene as possible and therefore shows the item I'm trying to centerOn to be in the top left corner of the view. I noticed it never hides any of the item I'm using centerOn with. The item is never centered in the view.
graphicsView->resetTransform();
double ratio = image->width() / (double)scale.width();
mapScene->addItem(pic);
if ( showOffset ) {
mapScene->addLine( offX/ratio, -graphicsView->height(), offX/ratio, graphicsView->height(), QPen(QColor(0,0,0)) );
mapScene->addLine( -graphicsView->width(), offY/ratio, graphicsView->width(), offY/ratio, QPen(QColor(0,0,0)) );
} //makes lines bigger than the view to ensure they take up the whole view, but stops centerOn to work propery in 4.6
graphicsView->centerOn(pic);
QGraphicsView::centerOn works as long as pic is the only item in the view. When the lines are added it's behavior changes when it should be irrelevant. Centering on an item is centering on an item. I'm hoping that I just did something silly that caused it to work in one and not the other... but the code is painfully simple.
graphicsView->resetTransform();
double ratio = image->width() / (double)scale.width();
mapScene->addItem(pic);
if ( showOffset ) {
mapScene->addLine( offX/ratio, -graphicsView->height(), offX/ratio, graphicsView->height(), QPen(QColor(0,0,0)) );
mapScene->addLine( -graphicsView->width(), offY/ratio, graphicsView->width(), offY/ratio, QPen(QColor(0,0,0)) );
} //makes lines bigger than the view to ensure they take up the whole view, but stops centerOn to work propery in 4.6
graphicsView->centerOn(pic);
QGraphicsView::centerOn works as long as pic is the only item in the view. When the lines are added it's behavior changes when it should be irrelevant. Centering on an item is centering on an item. I'm hoping that I just did something silly that caused it to work in one and not the other... but the code is painfully simple.