PDA

View Full Version : EventFilter show events returned



davinciomare
4th October 2016, 17:34
Hi i put the class eventfilter but how i can show in the main of my program the events of this filter. Class:

class FiltroDeEventosPersonalizado
: public QObject
{
Q_OBJECT

protected:

bool eventFilter(QObject *obj, QEvent *event) override;
};
Method :

bool
FiltroDeEventosPersonalizado::eventFilter(
QObject obj,
QEvent event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent keyEvent = static_cast<QKeyEvent>(event);
if( keyEvent->key() == Qt::Key_A )
qDebug() << "Tecla 'A' presionada";
return true;
}

return QObject::eventFilter(obj, event);
}
Main of my program:

#include <QCoreApplication>
#include <filtrodeeventospersonalizado.h>
#include <QDebug>


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//i want show the events with Qdebug
return a.exec();
}

anda_skoa
6th October 2016, 15:58
You need to install the event filter, e.g. on the application object.
See QObject::installEventFilter().

Cheers,
_