Make QGraphicsView Smooth CenterOn

I am not very new to Qt, but there are a few things that I don’t know ... I program in Python, but feel free to post your answers in ANY language.

So, I have several QGraphicsItem (s) located inside a QGraphicsScene , the scene is viewed with a regular QGraphicsView . Everything is fine.

My scene is very large, 10,000 x 10,000 pixels, all the graphic elements are scattered around.

For instance:

 # Creating Scene object.
 scene = QtGui.QGraphicsScene ()
 scene.setSceneRect (0, 0, 10000, 10000)
 # Creating View object.
 view = QtGui.QGraphicsView ()
 view.setScene (scene)

 # Adding some objects to scene.
 # scene.addItem (...)
 # ...

 # The list of items.
 items = scene.items ()

 # This is how i center on item.
 view.centerOn (some_item)
 view.fitInView (some_item, Qt.KeepAspectRatio)

My question is: how can I focus on each element using something similar to centerOn , but smoothly?

Currently centerOn is sending FAST to the next element, I want to move it slooowly, perhaps using QPropertyAnimation with an attenuation curve?

I tried moving the view to the next element using view.translate (1, 1) in a big loop, but the movement is too fast, like centerOn.

I tried to put some expectation with time.sleep (0.01) between translations, but window blocks until cicle exists ... so this is bad.

Many thanks!

+3
2

QTimeLine ( EaseInOutCurve), , , :

const QRectF r = ...calculate rect translated by timeline value and trajectory...
view->setSceneRect( r );
view->fitInView( r, Qt::KeepAspectRatio );

QLineF . , , QLineF:: pointAt().

SceneRect, fitInView, , .

+2

, setSceneRect. .

:

this- > ui- > graphicsView- > setSceneRect (0,0,100000000, 100000000); - > ui- > graphicsView- > centerOn (500,1030);

setSceneRect GraphicsView .

+1

Source: https://habr.com/ru/post/1773202/


All Articles