installeventfilter

Phil Thompson phil at riverbankcomputing.com
Tue Oct 11 06:34:02 EDT 2011


On Tue, 11 Oct 2011 11:57:28 +0200, Vincent Vande Vyvre
<vincent.vandevyvre at swing.be> wrote:
> Le 11/10/11 10:39, luca72 a �crit�:  
> helo i have this form how i can install the event filter:
> Class Form(QWidget, Ui_Form):
>  """
>  Class documentation goes here.
>  """
>  def __init__(self, parent = None):
>  """
>  Constructor
>  """
>  QWidget.__init__(self, parent)
>  self.setupUi(self)
> 
> Thanks
> 
>   MainWindow.eventFilter = self.event_filter
> 
>  ...
> 
>  def event_filter(self, object, event):
>  ������� # example: window is resized
>  ������� if event.type() == 14:
>  ����������� resize()
>  ����������� return True
> 
>  In your case, 'MainWindow' seems to be 'parent'

Monkey patching is not a good idea.

class EventFilter(QObject):
    def eventFilter(self, object, event):
        # example: window is resized
        if event.type() == QEvent.Resize:
            object.resize()
            return True

event_filter = EventFilter()
form = Form()

form.installEventFilter(event_filter)

Phil




More information about the Python-list mailing list