PDA

View Full Version : mousemove event in QGraphics



Dopt
4th July 2012, 09:13
I'm trying to make the program do something while mouse moving in my qgraphics scene/view.but it only works for mousePress event. However it also works when I'm moving my mouse outside the scene/view.
here is my code:

void Main::mousePressEvent(QMouseEvent *e) {...}
void Main::mouseMoveEvent(QMouseEvent *e) {...}

pkj
5th July 2012, 05:12
mouse move events only occur when a button is pressed by default, you need to setMouseTracking(true) on the view for the move events to generated in the first place, so that it can forward those to the scene.
Alternatively, if you don't need the translation to scene coordinates, you could reimplement the mouseMoveEvent in the view directly rather than in your scene. But in this case, make sure you call the base class QGraphicsView::mouseMoveEvent in your implementation, so that hover events are properly generated for the items in your scene.

Dopt
5th July 2012, 09:33
okay, thanks!