title: Redirecting an Qt mouse message in viewportEvent to another window is not working
body: <p>I want to implement an extended "QScrollArea" widget that supports scrolling the scrollbar (contents) with the mouse by dragging the mouse somewhere within the widget. For this purpose I want to ignore any child widgets so that the focus don't accidently goes to some of the children.</p>
  
  <p>My solution (which is not working) is to set content widget attribute <code>WA_TransparentForMouseEvents</code> so that all the mouse events goes to viewportEvent() method in my <code>QScrollAreaEx</code>. Here I want to handle the mouse messages. For example I could determine if the intention was to drag the scrollbar position or to interact with some of the child widgets (activate, select, move caret, ...).</p>
  
  <p>My first try was to redirect the messages <strong>MouseButtonPress</strong> and <strong>MouseButtonRelease</strong> events only to the child widget underneath (widget()->childAt(e->pos())) which had been focused if <code>WA_TransparentForMouseEvents</code> were not set. However that didn't worked, none of the widgetd received the focus. But why?</p>
  
  <pre><code>bool viewportEvent(QEvent* e) {
      bool IsMouseEvent = e-&gt;type() == QEvent::MouseButtonPress || e-&gt;type() == QEvent::MouseButtonRelease || e-&gt;type() == QEvent::MouseMove;
      QMouseEvent* me = (QMouseEvent*) e;
  
      bool IsHandled = false;
  
      if (IsMouseEvent) {
          if (e-&gt;type() == QEvent::MouseButtonPress) {
              _PressEvent = *me;
              IsHandled = true; // Eating press event
          } else if (e-&gt;type() == QEvent::MouseButtonRelease) {
              QPoint PressPoint = _PressEvent.pos();
              widget()-&gt;setAttribute(Qt::WA_TransparentForMouseEvents, false);
              QWidget* w = widget()-&gt;childAt(PressPoint);
              if (w) {
                  QPoint p1 = w-&gt;mapFrom(widget(), _PressEvent.pos());
                  QPoint p2 = w-&gt;mapFrom(widget(), me-&gt;pos());
                  QMouseEvent* e1 = new QMouseEvent(QEvent::MouseButtonPress, p1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                  QMouseEvent* e2 = new QMouseEvent(QEvent::MouseButtonRelease, p2, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                  QCoreApplication::postEvent(w, e1);
                  QCoreApplication::postEvent(w, e2);
              }
              widget()-&gt;setAttribute(Qt::WA_TransparentForMouseEvents, true);
          }
      }
      if (IsHandled) return true;
      return QScrollArea::viewportEvent(e);
  }
  </code></pre>
  
  <p>Second test was:</p>
  
  <pre><code>bool viewportEvent(QEvent* e) {
      bool IsMouseEvent = e-&gt;type() == QEvent::MouseButtonPress || e-&gt;type() == QEvent::MouseButtonRelease || e-&gt;type() == QEvent::MouseMove;
      QMouseEvent* me = (QMouseEvent*) e;
  
      bool IsHandled = false;
  
      if (IsMouseEvent) {
          if (e-&gt;type() == QEvent::MouseButtonPress) {
              _PressEvent = *me;
              IsHandled = true; // Eating press event
          } else if (e-&gt;type() == QEvent::MouseButtonRelease) {
              QPoint PressPoint = _PressEvent.pos();
              widget()-&gt;setAttribute(Qt::WA_TransparentForMouseEvents, false);
              QWidget* w = widget()-&gt;childAt(PressPoint);
              if (w &amp;&amp; w != widget()) {
                  QCoreApplication::sendEvent(widget(), &amp;_PressEvent);
                  QCoreApplication::sendEvent(widget(), e);
              }
              widget()-&gt;setAttribute(Qt::WA_TransparentForMouseEvents, true);
          }
      }
      if (IsHandled) return true;
      return QScrollArea::viewportEvent(e);
  }
  </code></pre>
  
  <p>None of them was working. Why does the redirection not work. Is there a better solution for my purpose?</p>