You can use a custom event filter to handle all keyboard and mouse events received by your application before they are passed to child widgets.
class MyEventFilter : public QObject
{
Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *ev)
{
if(ev->type() == QEvent::KeyPress ||
ev->type() == QEvent::MouseMove)
resetMyTimer();
return QObject::eventFilter(obj, ev);
}
}
Then use something like
MyApplication app(argc, argv);
MyEventFilter filter;
app.installEventFilter(&filter);
app.exec();
It definitely works (I tried it myself).
EDIT: And thank you very much ereOn for pointing out that my early decision was not very useful.
source
share