If you search google for how to capture events, most articles you get will teach you install event filter for child objects, then rewrite the eventFilter function in parent. This way you will intercept all events in the parent’s eventFilter function before they reach the child objects. But how to get all events for a widget itself? The answer is install event filter for the widget itself and overload the eventFilter function in the widget’s subclass,i.e., in the constructor of MyWidget:
installEventFilter(this);
Rewrite the eventFilter in the definition of MyWidget
bool eventFilter(QObject * watched, QEvent * event)
{
}
Sometimes it is useful to get all events happening on a widget so you can investigate what is happening. For example, if you want to simulate a mouse drag-drop event, you may find just simulating the mousePress, mouseMove, and mouseRelease events is not enough. By using this method, you can know other events that is happening at drag-drop time.
Comments are closed, but trackbacks and pingbacks are open.