[PyQt] Various problems with QGraphicsView

Matt Newell newellm at blur.com
Tue Jun 3 18:36:15 BST 2008


On Tuesday 03 June 2008 10:11:51 Phil Thompson wrote:
> 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


In this case that isn't the problem.  I was getting incorrect results from 
QMouseEvent::buttons() inside qt code after setting breakpoints with gdb, 
before the event ever reached pyqt code.

Matt


More information about the PyQt mailing list