PDA

View Full Version : Moving QGraphicsItem with mouse



BrainFreeze
10th February 2011, 01:22
I've starting experimenting with QGraphicsScene, QGraphicsView, and have a problem I don't understand. I can move a QGraphicsItem with the mouse, but it can be moved outside of the scene (sceneRect?). I noticed this when I zoom out to see the whole scene. Is there a way to keep the item inside the scene?

tbscope
10th February 2011, 04:40
Yes, check the coordinates of the item and prevent them to get outside the scene.

totem
10th February 2011, 08:04
to monitor graphicsItem position change, take a look at QGraphicsItem::itemChange()

BrainFreeze
10th February 2011, 17:28
to monitor graphicsItem position change, take a look at QGraphicsItem::itemChange()

Being a beginner, I haven't ever written a custom item, no idea how. Can you direct me to a tutorial for that? As for my beginning experiments, I'm using a QGraphicsItem rather than a custom item. Does your suggestion apply to that, too? This is all new to me, so any tutorials you can suggest would be helpful. Thanks in advance.

wysota
10th February 2011, 21:54
Just follow the link you were given.

BrainFreeze
10th February 2011, 22:38
Just follow the link you were given.

That's not a tutorial, it's just a code snippet

wysota
10th February 2011, 22:43
So... you expect to have a tutorial about what? Using a single method? How would such a tutorial be different from the documentation of this method showing an example of use?

BrainFreeze
10th February 2011, 23:12
So... you expect to have a tutorial about what? Using a single method? How would such a tutorial be different from the documentation of this method showing an example of use?

I requested a tutorial on how to create a custom item. I've never done that, and have no idea how. Sorry if I wasn't clear on that.

wysota
10th February 2011, 23:21
QGraphicsItem

JohannesMunk
11th February 2011, 00:48
Try that link! Suspense rises until you hit:

"To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect (http://doc.trolltech.com/latest/qgraphicsitem.html#boundingRect)(), which returns an estimate of the area painted by the item, and paint (http://doc.trolltech.com/latest/qgraphicsitem.html#paint)(), which implements the actual painting. For example: "

Don't take this the wrong way! Good luck with your first custom item!

Johannes