[PyQt] How can I capture some mouse events but ignore others?

Phil Thompson phil at riverbankcomputing.com
Fri Mar 6 15:55:40 GMT 2009


On Fri, 6 Mar 2009 07:50:57 -0800, Brian Kelley <kelley at eyesopen.com>
wrote:
> Hmm, that is what I would have thought, you could always try calling the
> table widget directory in the case of ignores.  Actually, I'll bet you
have
> to do this since you have overridden the mousePressEvent function.
> 
> QtGui.QTableWidget.mousePressEvent(event)
> 
> 
> On 3/6/09 10:47 AM, "Marc Nations" <mnations.lists at gmail.com> wrote:
> 
> Thanks, wasn't aware of being able to accept events.
> 
> So I tried this, instead of waiting for release I moved it up to when a
> button is pressed to get a better idea of what was happening. I tried
this:
> 
>     def mousePressEvent(self, event):
>         if event.button() == QtCore.Qt.RightButton:
>             event.accept()
>             self.rightClickMenu(event)
>         else:
>             event.ignore()
> 
> According to the docs for the mouse events it should do this: "You should
> call ignore
>
<http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#ignore>
> () if the mouse event is not handled by your widget. A mouse event is
> propagated up the parent widget chain until a widget accepts it with
accept
>
<http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#accept>
> (), or an event filter consumes it."
> 
> My understanding of that is once I ignore the event it should
automatically
> try the base class, which in this case is the base table widget. However
> using that code the left-click is basically disabled and nothing happens.
> So the event just seems to get dropped at that point. Is there something
> else I need to do to make the event retreat in the right direction?

I think you are getting confused between the class hierarchy and the widget
hierarchy. An ignored event is passed to the parent widget not the base
class.

Phil


More information about the PyQt mailing list