PDA

View Full Version : [QGraphicsView] centerOn() with smooth scrolling



And_re
24th May 2010, 16:17
Is there any way to get something similar to the function centerOn() but with smooth scrolling?
I have the scene (-640, -780, 1280, 1560) and one item (football player) that is following the cursor all the time.
I want the view to display this item just as centerOn() but without jumps when scrolling. It's because centerOn() uses int instead of qreal. I have tried many things, for example: setSceneRect( sceneRect().translated( diff.x, diff.y ) ) where diff is difference between item position and mapToScene( geometry().center() ) but it doesn't work as expected.

tbscope
24th May 2010, 20:04
It's because centerOn() uses int instead of qreal.

Not according to the documentation:
http://doc.qt.nokia.com/4.6/qgraphicsview.html#centerOn

And_re
24th May 2010, 20:48
But I talk about implementation of this function in sources.
And there is something like that:
horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));
verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));

JD2000
25th May 2010, 11:29
use translate() rather than centreOn().