Reputation: 1269
I need to get the list of all events fired in a Qt Widget ( Qt C++) like an utility which can capture all events or some function which will be called and the event details to be passed to the function every time an event is fired.
Can somebody tell me how to do this or is there any free utility available for this purpose ?
Upvotes: 2
Views: 2906
Reputation: 7258
QObject::installEventFilter is what you want. You can see all events coming into an object.
If you need to see all events for everything, you can install event filter on QApplication, see documentation to QCoreApplication::notify:
Installing an event filter on QCoreApplication::instance(). Such an event filter is able to process all events for all widgets, so it's just as powerful as reimplementing notify(); furthermore, it's possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets. Note that application event filters are only called for objects that live in the main thread.
Upvotes: 3
Reputation: 9821
If you make a class derived from QWidget
(let's call it RecordingWidget
) you can reimplement it's event()
function to record in whatever manner you'd like (maybe keep a log in a static member of RecordingWidget
) and then continue to pass the event to QWidget
's default event
function:
bool RecordingWidget::event(QEvent *event)
{
// Record stuff
...
// Send the event through QWidget's default event implementation
return QWidget::event(event);
}
Upvotes: 1