Reimplement
mousePressEventon the scene, rather than the view.
That way, the
eventargument will be a
QGraphicsSceneMouseEvent, which has several useful
additional functions - including
scenePos, which does exactly
what you want:
class graphicsScene(QtGui.QGraphicsScene): def __init__ (self, parent=None): super(graphicsScene, self).__init__ (parent) def mousePressEvent(self, event): super(graphicsScene, self).mousePressEvent(event) item = graphicsItem() position = QtCore.QPointF(event.scenePos()) - item.rectF.center() item.setPos(position.x() , position.y()) self.addItem(item)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)