Hi,
Here is a piece of qt4 code written in python. Basically, a rectangle is painted when I press the mouse button. But the problem is the qgraphicsview will re-position the view, so the item painted is not under where the mouse is pressed. How do I solve this?

Qt Code:
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtCore import *
  3. import sys
  4.  
  5. class MapView(QGraphicsView):
  6.  
  7. def __init__(self, parent = None):
  8. QGraphicsView.__init__(self, parent)
  9.  
  10. def mousePressEvent(self, event):
  11. mousePos = self.mapToScene(event.pos())
  12. self.scene().addRect(mousePos.x(), mousePos.y(), 10, 10)
  13.  
  14. app = QApplication(sys.argv)
  15. scene = QGraphicsScene()
  16. view = MapView()
  17. view.setScene(scene)
  18. view.setFixedSize(400, 300)
  19. view.show()
  20. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode