The eventFilter does not just operate on a single object. You can set something to be an event filter to 100 objects if you want. But you will usually want to check what the object is to ensure you handle it in the appropriate way:
# check for a specific instance if obj is foo: # check for a number of instance types: if isinstance(obj, (str, int, float, list, tuple, dict)): # duck typing if hasattr(obj, "someAttribute"): You can set any QObject subclass to be an event filter of any other QObject On Apr 22, 2013, at 8:22 PM, Tuan Nguyen wrote: > I feel bad about it, just type in on a whim :( . > And, there are 2 last thing about eventFilter i'm confusing about, can you > confirm it for me? :D > > def eventFilter(self,obj,event): > .....if obj is item: > > This is quite a pain since eventFilter can only chose one specify item to > filter on. I try change the method, like in, isinstance but no luck :( > > The second thing is, sceneEventFilterEvent not working on itself, and its > child either? > > :3 > > > On Mon, Apr 22, 2013 at 3:00 PM, Justin Israel <[email protected]> wrote: > Haha I am just teasing. You can't really delete messages off the message > group ;-) > > On Apr 22, 2013 6:48 PM, "Tuan Nguyen" <[email protected]> wrote: > eh, sorry about that. I though i delete the last one, and send a new one :D > > > On Mon, Apr 22, 2013 at 12:02 PM, Justin Israel <[email protected]> > wrote: > No problem, David :-) > > On Apr 22, 2013 3:35 PM, "Tuan Nguyen" <[email protected]> wrote: > Ah, everything work as expect, thank a ton Justin :3 > > > On Mon, Apr 22, 2013 at 1:57 AM, Justin Israel <[email protected]> wrote: > If you call the super class method then of course it will pass the event up. > The way to prevent it from bubbling up is to do event.accept() and return > True from the eventFilter. > On Apr 22, 2013 1:39 AM, "Tuan Nguyen" <[email protected]> wrote: > Thanks > But those events drive my crazy :( i don't know why it keep jump up to Maya's > keyEvent, even i put an eventFilter on. When i reimplement QGraphicsView's > keyPressEvent, i have to skip calling events super class, else Maya's hotkey > still working as well. > > > On Sun, Apr 21, 2013 at 3:51 AM, Justin Israel <[email protected]> wrote: > Glad you got the problem resolved. > > For the other question, don't forget to check the docs! > http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#events > > On Apr 21, 2013 5:21 AM, "Tuan Nguyen" <[email protected]> wrote: > Ah, about that. I just got it work, i really really sorry, that was my > mistake :( > However can i ask another question? Can i use the eventFilter on > QGraphicsItem? they are not widget .... and i have to make an except on it > when call the QGraphicsView's keyPressEvent :( > > > > On Sat, Apr 20, 2013 at 2:19 PM, Justin Israel <[email protected]> wrote: > If you are installing the event filter on an object and you have defined the > eventFilter() method, then I am not sure why it would not get called. Please > post a small, concise, fully working example of the problem, so we can test > it for you. > > > On Apr 19, 2013, at 7:53 PM, Tuan Nguyen wrote: > >> oh and i'm sorry. The script in pastebin missing the event.accept() line, >> but still, the eventFilter is not working :( >> >> >> >> On Fri, Apr 19, 2013 at 2:35 PM, Tuan Nguyen <[email protected]> wrote: >> yes, i try it too, the print statement. But nothing is print out, so i guess >> its not working? >> >> >> >> On Fri, Apr 19, 2013 at 1:52 PM, Justin Israel <[email protected]> >> wrote: >> Did you confirm that the eventFilter() is being called? Put a print >> statement right after: >> if obj is self.GraphicsView >> >> Also remember to do event.accept() if you are handling the event yourself >> so that it doesn't bubble up. >> >> >> >> On Fri, Apr 19, 2013 at 6:36 PM, Tuan Nguyen <[email protected]> wrote: >> Sorry to dig this up, at that time, i were using the first way you told me, >> it works fine so i think i will left it like that for a while and come back >> after had finished other part. But somehow, i think the eventFilter is not >> working at all, >> >> >> self.GraphicsView.mousePressEvent = self.qView_mousePressEvent >> >> def eventFilter(self, obj, event): >> if obj is self.GraphicsView: >> if event.button() != QtCore.Qt.LeftButton: >> self.qView_mousePressEvent(event) >> return True >> >> in the mousePressEvent i had a case when event.button() == >> QtCore.Qt.LeftButton, it will return the QGraphicsView,mousePressEvent. And >> if i remove it, the leftMousePressEvent is gone too >> >> I also try install the eventFilter on GraphicsView but no luck :( >> >> http://pastebin.com/SbJfsHTG >> >> >> On Fri, Mar 1, 2013 at 3:01 AM, Tuan Nguyen <[email protected]> wrote: >> Maybe i had done something funny when reimplement mouseEvent, so the result >> after calling class out still wrong. I will check the script again, also >> thank for show me how to use eventFilter. I try to go with it at first >> place, but since time is short, i chose replace the bounding method instead >> :D >> >> Thank for your reply, Justin >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Python Programming for Autodesk Maya" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> >> To post to this group, send email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/rUzeXlRweDI/unsubscribe?hl=en-US. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
