QEvent

Event objects passed into QWidget::event(QEvent*) method as an argument are automatically casted into its real instance. There is no need to “re-cast” it anymore.

In the following example you can see that there is used QKeyEvent sepcific method text() despite that the C++ prototype of event() method requires QEvent instance. And $event variable can be used as a QEvent instance as well (parent's event() method call).

Example 2.4. QEvent automatic "casting"

class MyWidget inherits QWidget
{
  event($event)
  {
    if ($event.type() == QEvent::KeyPress)
      printf("key pressed: %s\n", $event.text());

    return QWidget::$.event($event);
  }
}
          

if your implementation of MyWidget::event($event) will get a QKeyEvent, the the QKeyEvent will be passed as an argument $event.