title: Propagate custom QEvent to parent widget in Qt/PyQt
body: <p>Fist, apologies for the length of the question.</p>
  
  <p>I am trying to propagate custom Qt event from child widgets to a top parent widget in order to trigger some action based on event type instead of linking signals.</p>
  
  <p>Qt docs suggests that every event posted with <code>postEvent()</code> that have <code>accept()</code> and <code>ignore()</code> methods can be propagated (meaning each <code>QEvent</code> subclass).</p>
  
  <p>I have tried to override <code>customEvents</code> method instead of <code>events</code> but to no avail.</p>
  
  <h2>Python</h2>
  
  <p>I've tried this in Python using PyQt4 (Qt version is 4.6).</p>
  
  <pre><code>from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  
  class Foo(QWidget):
      def doEvent(self):
          QApplication.postEvent(self, QEvent(12345))
  
      def event(self, event):
          event.ignore()
          return False
  
  class Bar(QWidget):
      def __init__(self, *args, **kwargs):
          super(Bar, self).__init__(*args, **kwargs)
          self.foo = Foo(self)
          layout = QHBoxLayout()
          layout.addWidget(self.foo)
          self.setLayout(layout)
  
      def event(self, event):
          if event.type() == 12345:
              self.someEventHandler()
          return True
  
      def someEventHandler(self):
          print 'Handler in {0}'.format(self.__class__.__name__)
  
  if __name__=='__main__':
      app = QApplication([''])
      bar = Bar()
      bar.show()
      bar.foo.doEvent()
      app.exec_()
  </code></pre>
  
  <p>In this example <code>Bar.someEventHandler()</code> would only trigger if event was posted with <code>self.parent()</code> as the first argument like so:</p>
  
  <pre><code>def doEvent(self):
      QApplication.postEvent(self.parent(), QEvent(12345))
  </code></pre>
  
  <p>Which is understandable since the event is passed directly to receiving object.</p>
  
  <h2>C++</h2>
  
  <p>Similar example in C++:</p>
  
  <p><strong>foobar.h</strong></p>
  
  <pre><code>#ifndef FOOBAR_H
  #define FOOBAR_H
  
  #include &lt;QtGui&gt;
  
  class Foo : public QWidget
  {
      Q_OBJECT
  
  public:
      Foo(QWidget *parent = 0);
      void doEvent();
      bool event(QEvent *);
  };
  
  
  class Bar : public QWidget
  {
      Q_OBJECT
  
  public:
      Bar(QWidget *parent = 0);
      Foo *foo;
      bool event(QEvent *);
  };
  
  #endif // FOOBAR_H
  </code></pre>
  
  <p><strong>foobar.cpp</strong></p>
  
  <pre><code>#include "foobar.h"
  
  Foo::Foo(QWidget *parent)
       : QWidget(parent) {}
  
  void Foo::doEvent() {
      QEvent *event = new QEvent(QEvent::User);
      QApplication::postEvent(this, event);
  }
  
  bool Foo::event(QEvent *event)
  {
      event-&gt;ignore();
      return QWidget::event(event);
  }
  
  Bar::Bar(QWidget *parent)
       : QWidget(parent)
   {
      foo = new Foo(this);
  }
  
  bool Bar::event(QEvent *event)
  {
      if (event-&gt;type() == QEvent::User) {
          qDebug() &lt;&lt; "Handler triggered";
          return true;
      }
      return QWidget::event(event);
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;QtGui&gt;
  #include "foobar.h"
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      Bar bar(0);
      bar.show();
      bar.foo-&gt;doEvent();
      return app.exec();
  }
  </code></pre>
  
  <p>Same as in python this only works if event is passed directly to an object.</p>
  
  <pre><code>void Foo::doEvent() {
      QEvent *event = new QEvent(QEvent::User);
      QApplication::postEvent(this-&gt;parentWidget(), event);
  }
  </code></pre>
  
  <p>Perhaps I missed the point, is it possible that only Key and Mouse events are propagated upwards?</p>