mouseMoveEvent not working in QGraphicsScene
I am trying to implement a paint program in PyQt4. In the QGraphicsScene, I use the mouseMoveEvent to draw lines connecting the consecutive mouse co-ordinates.
The code is as follows:def mouseMoveEvent(self, event):
x1 = event.pos().x()
y1 = event.pos().y()
self.addLine(self.x0, self.y0, x1, y1, self.pen)
self.x0, self.y0 = x1, y1
x0, y0 are initialized as 0,0.
The problem I encounter is that, when I click the mousebutton a single point is drawn at (0,0), and no more drawing takes place.
The same mouseMoveEvent works perfectly in QGraphicsView. Is there anything that I'开发者_高级运维m missing?I figured out the problem. The above code is fine, except that event.pos()
does not work in QGraphicsScene. Inorder to capture the mouseEvent's co-ordinates in QGraphicsScene, we must use event.scenePos()
精彩评论