PDA

View Full Version : view, scene and one moving item all around the scene/view...



KBuschder
10th June 2014, 12:43
hey folks,

will make it short...read all your answers here, couldn't find any solution for my question. I think I don't need to post any code snippets..this problem is to trivial.. :(

In my widget, I create a scene - in this scene, there is a view. Then, I add a self-created QGraphicsItem. This QGraphicsItem is movable like a car or so. Means, you can press W,A,S,D and this item moves forward,backward, sideways(rotates)...so far so good. Functions properly.

But I am totally not able to make ensureVisible, centerOn, fitInView eg. function properly. Means, everytime my item is about to leave the visible area, the portview or so should be readjusted...

You know what I mean? Thanks for your attention!

greetings, Klaus

wysota
10th June 2014, 15:37
What have you tried so far?

KBuschder
10th June 2014, 16:01
Hello, thank you for your response :)

As I said, I subclassed QGraphicsItem with the paint() and advanced()-functions. In paint() I call ensureVisible(boundingRect()) ... So far..this seems to function..but not with the margins for x and y. The given margins seem not to be recognized...

I've tried to place ensureVisible() in the constructor, in main(), in advance(), ... tried it with a given sceneRect and without - and same with centerOn and fitInView .
Tried it to map some coordinates to the scene, tried to discover when my item leaves the scene/view ... nothing.

KBuschder
11th June 2014, 09:04
Got the solution.

I only had to set the sceneRect AND place the view/item with centerOn in the middle of the scene, so ensureVisible works quite fine!

Thank you for your interest!