[PyQt] Various problems with QGraphicsView

Phil Thompson phil at riverbankcomputing.com
Tue Jun 3 18:11:51 BST 2008


On Tuesday 03 June 2008 5:50:50 pm Luke Campagnola wrote:

>  - It appears that the event object that gets passed to the
> mouseEvent functions is being reused. This caused an unexpected (but
> easily fixed) problem for me: In order to allow scene panning/scaling,
> I need to record the event.pos() for every mouse event so that I can
> compare the previous event position to the current event position.
> Since the event object is reused, however, I find that the position I
> stored as the "previous position" has already been updated to the
> current position. For example:
>  ## Does not work
>  self.lastMousePosition = event.pos()
>  ## Workaround
>  self.lastMousePosition = QPoint(event.pos().x(), event.pos().y())

You just need to do...

self.lastMousePosition = QPoint(event.pos())

This is a fairly common problem caused by '=' in Python meaning something 
different to '=' in C++. In the latter you would implicitly invoke the copy 
ctor, but Python requires you to be explicit.

It's on the TODO list to automatically make a copy of a const reference.

Phil


More information about the PyQt mailing list