PDA

View Full Version : Can anyone give me a example on using QGraphicsScene::mouseMoveEvent?



fulin
13th January 2011, 08:33
Hello,

Can anyone give me a example on using QGraphicsScene::mouseMoveEvent?

My application is

* myscene->addPixmap(QPixmap::fromImage(myimage));
* ui->graphicsView->setScene(myscene);
* ui->graphicsView->show();

For me it seems no way to get mouse event on this displayed image. I want to draw lines on this displayed image.

I also have the lines in my application.h

protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);


Can anyone give me an example or tips? Thank you in advance!

JohannesMunk
13th January 2011, 11:57
Hi there!

Have a look at the diagram-scene example: http://doc.trolltech.com/latest/graphicsview-diagramscene.html

You should also consider creating a subclass of QGraphicsPixmapItem and reimplementing its mouse events instead of the scenes.

That way you would hasslefree only get the events inside the item and in item coordinates. Depends on what you want to achieve..

HIH

Johannes

fulin
14th January 2011, 08:55
Hi Johannes,

Thank you very much! It is very helpful tip.:)