Hi.

If I want to create a kind of "Ms Paint" using GraphicsView, GraphicsScene and Items, which class I have to reimplement to get mousepress and mousemove events? GraphicsView or Scene?

I tried to use Scene, but even with it in 600x500 WidthxHeight ever place that I click the coordinates are the same 0,0 and the follow code dont draw any thing, in this case, a line.

Qt Code:
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtCore import *
  3.  
  4. class GraphicsScene(QGraphicsScene):
  5. def __init__(self, parent = None):
  6. super(GraphicsScene, self).__init__(parent)
  7.  
  8. self.setSceneRect(0, 0, 600, 500)
  9. self.setBackgroundBrush(QColor(242, 251, 235))
  10.  
  11.  
  12. def mousePressEvent(self, e):
  13. self.pointBegin = self.pointEnd = e.pos()
  14.  
  15. self.line = QGraphicsLineItem(QLineF(self.pointBegin, self.pointEnd))
  16. self.line.setFlags(QGraphicsItem.ItemIsMovable)
  17.  
  18. self.addItem(self.line)
  19.  
  20. def mouseMoveEvent(self, e):
  21. self.pointEnd = e.pos()
  22.  
  23. self.line.setLine(QLineF(self.pointBegin, self.pointEnd))
  24.  
  25.  
  26. def mouseReleaseEvent(self, e):
  27. self.line.setLine(QLineF(self.pointBegin, self.pointEnd))
To copy to clipboard, switch view to plain text mode