PDA

View Full Version : how to catch the mouse event in the QGrahphicsScene object?



ggs0110
14th July 2007, 04:26
hi All,
I have some questions ,need your help!
the codes as follows:

QGraphicsScene* scene=new QGraphicsScene(this);
QGraphicsView* mainview=new QGrahphhicsView(scene);

QGraphicPixmapItem* piximg=scene->addPixmap(QPixmap(filename));//filename is the opened image filename.
.......

the question are:
1: how to catch the mouse events in the scene? should I reimpliment some methods a class derived from the class QGraphicsScene?
2:if I want to get a part of the image rectangle field ,how can i do it?

thank you!:confused:

marcel
14th July 2007, 16:43
1: how to catch the mouse events in the scene? should I reimpliment some methods a class derived from the class QGraphicsScene?

See the mouse events from QAbstractScrollArea. You can override those. Just make sure to convert the event mouse position(which is the viewport position) to scene coordinates. This way you get scene coordinates.



2:if I want to get a part of the image rectangle field ,how can i do it?

[/CODE]
One solution is to create a new pixmap with the dimensions of the section and then just take the item's pixmap use a QPainter to write the desired data to destination.
It is just a matter of translating the painter coordinate system.

Regards

ggs0110
4th August 2007, 04:31
thank you ,I will try it...